Index: ossp-pkg/fsl/fsl.pod RCS File: /v/ossp/cvs/ossp-pkg/fsl/fsl.pod,v rcsdiff -q -kk '-r1.29' '-r1.30' -u '/v/ossp/cvs/ossp-pkg/fsl/fsl.pod,v' 2>/dev/null --- fsl.pod 2003/05/22 14:01:55 1.29 +++ fsl.pod 2003/06/30 11:13:08 1.30 @@ -202,11 +202,17 @@ The B channel opens a file at the given I and passes messages poured in from upper channels to this file. If the file at the given path already exists, additional data is either appended -(I=1) or the existing file is truncated (I=0). The -desired permissions of the file can be set. +(I=1 or I=0>) or the existing file is truncated +(I=0 or I=1>). The desired permissions of the file can be +set. Both append and trunc work equally well but append is obsolete and +might be removed in the future. Both options can be specified together +as long as they are set different. L2 versions which know the trunc +option default to append mode while previous versions only having the +append option defaulted to truncate mode. o file (STR path m - INT append o [0=truncate|1=append] =1 + INT append o [0=no|1=yes] =1 + INT trunc o [0=no|1=yes] =0 INT perm o [octal] =0644 ) @@ -449,17 +455,14 @@ -> { critical: file( path="@l_prefix@/var/inn/log/news.crit", - append=1, perm=0644 ); error: file( path="@l_prefix@/var/inn/log/news.err", - append=1, perm=0644 ); notice: file( path="@l_prefix@/var/inn/log/news.notice", - append=1, perm=0644 ) } @@ -474,7 +477,6 @@ ) -> file( path="@l_prefix@/var/fsl/default.log", - append=1, perm=0644 ) }; Index: ossp-pkg/l2/l2.pod RCS File: /v/ossp/cvs/ossp-pkg/l2/l2.pod,v rcsdiff -q -kk '-r1.14' '-r1.15' -u '/v/ossp/cvs/ossp-pkg/l2/l2.pod,v' 2>/dev/null --- l2.pod 2003/01/06 11:41:51 1.14 +++ l2.pod 2003/06/30 11:13:08 1.15 @@ -118,7 +118,7 @@ noop -> { debug: prefix(prefix="[%d-%m-%Y/%H:%M:%S] ") -> buffer(size=16384) - -> file(path=foo.log, append=1); + -> file(path=foo.log, trunc=0); error: syslog(ident=foo, facility=user, remotehost=syslog.example.com, target=remote); Index: ossp-pkg/l2/l2_ch_file.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_file.c,v rcsdiff -q -kk '-r1.25' '-r1.26' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_file.c,v' 2>/dev/null --- l2_ch_file.c 2003/01/06 11:41:51 1.25 +++ l2_ch_file.c 2003/06/30 11:13:08 1.26 @@ -39,6 +39,7 @@ int fd; char *path; int append; + int trunc; int perm; } l2_ch_file_t; @@ -54,7 +55,8 @@ /* initialize configuration with reasonable defaults */ cfg->fd = -1; cfg->path = NULL; - cfg->append = TRUE; + cfg->append = -1; + cfg->trunc = -1; cfg->perm = (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); /* link private channel configuration into channel context */ @@ -74,11 +76,13 @@ /* feed and call generic parameter parsing engine */ L2_PARAM_SET(pa[0], path, STR, &cfg->path); L2_PARAM_SET(pa[1], append, INT, &cfg->append); - L2_PARAM_SET(pa[2], perm, INT, &cfg->perm); - L2_PARAM_END(pa[3]); + L2_PARAM_SET(pa[2], trunc, INT, &cfg->trunc); + L2_PARAM_SET(pa[3], perm, INT, &cfg->perm); + L2_PARAM_END(pa[4]); l2_channel_env(ch, &env); rv = l2_util_setparams(env, pa, fmt, ap); + return rv; } @@ -89,16 +93,42 @@ int mode; mode_t mask; + /* "append" backward compatibility; only cfg->trunc is used in the code + * make sure append/trunc either both use defaults, both are set different, or only one is set + * + * truth table for user input, append, trunc => resulting trunc + * -----------------+------+------+------------------ + * -1 -1 0 (default) + * trunc=0 -1 0 0 + * trunc=1 -1 1 1 + * append=0 0 -1 1 + * append=0, trunc=0 0 0 ERROR + * append=0, trunc=1 0 1 1 + * append=1 1 -1 0 + * append=1, trunc=0 1 0 0 + * append=1, trunc=1 1 1 ERROR + */ + if (cfg->append >= 1) + cfg->append = 1; /* reduce to -1 (undef), 0 (no), 1 (yes) */ + if (cfg->trunc >= 1) + cfg->trunc = 1; /* reduce to -1 (undef), 0 (no), 1 (yes) */ + if ( cfg->append != -1 + && cfg->trunc != -1 + && cfg->append == cfg->trunc) /* collision */ + return L2_ERR_USE; + if ( cfg->trunc == -1) + cfg->trunc = (1 - cfg->append) & 1; + /* make sure a path was set */ if (cfg->path == NULL) return L2_ERR_USE; /* open channel file */ mode = O_WRONLY|O_CREAT; - if (cfg->append) - mode |= O_APPEND; - else + if (cfg->trunc == 1) mode |= O_TRUNC; + else + mode |= O_APPEND; mask = umask(0); cfg->fd = open(cfg->path, mode, cfg->perm); umask(mask); Index: ossp-pkg/l2/l2_test.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_test.c,v rcsdiff -q -kk '-r1.53' '-r1.54' -u '/v/ossp/cvs/ossp-pkg/l2/l2_test.c,v' 2>/dev/null --- l2_test.c 2003/02/11 07:51:28 1.53 +++ l2_test.c 2003/06/30 11:13:09 1.54 @@ -89,7 +89,7 @@ " filter(regex=hecking, negate=0)" " -> prefix(prefix=\"[%d-%m-%Y/%H:%M:%S] %L test[%P]: \", timezone=local)" " -> buffer(size=800)" - " -> file(path=l2_test.log, append=1, perm=0644) ;" + " -> file(path=l2_test.log, trunc=0, perm=0644) ;" /* " syslog(ident=L2-Test, facility=user, " " remotehost=localhost, logpid=1, target=remote)" @@ -124,7 +124,7 @@ /* create file channel */ if ((rv = l2_channel_create(&chFile, env, "file")) != L2_OK) die(env, rv, "failed to create file channel"); - if ((rv = l2_channel_configure(chFile, "path=l2_test.log, append=%d,perm=%d", TRUE, 0644)) != L2_OK) + if ((rv = l2_channel_configure(chFile, "path=l2_test.log, trunc=%d,perm=%d", 0, 0644)) != L2_OK) die(env, rv, "failed to configure file channel"); if ((rv = l2_channel_levels(chFile, L2_LEVEL_UPTO(L2_LEVEL_INFO), L2_LEVEL_NONE)) != L2_OK) die(env, rv, "failed to level of smtp channel");