version 1.1.1.1.2.2, 2011/05/20 16:26:53
|
version 1.1.1.1.2.5, 2011/05/20 17:03:28
|
Line 18 FILE *lf;
|
Line 18 FILE *lf;
|
static inline void |
static inline void |
Log(int lvl, const char *fmt, ...) |
Log(int lvl, const char *fmt, ...) |
{ |
{ |
va_list lst; | va_list lst, cp; |
|
|
if (lvl <= Verbose) { |
if (lvl <= Verbose) { |
va_start(lst, fmt); |
va_start(lst, fmt); |
|
va_copy(cp, lst); |
vfprintf(lf, fmt, lst); |
vfprintf(lf, fmt, lst); |
vsyslog(LOG_WARNING, fmt, lst); |
|
va_end(lst); |
va_end(lst); |
|
fprintf(lf, "\n"); |
|
vsyslog(LOG_WARNING, fmt, cp); |
|
va_end(cp); |
} |
} |
} |
} |
|
|
static inline void |
static inline void |
Err(const char *fmt, ...) |
Err(const char *fmt, ...) |
{ |
{ |
va_list lst; | va_list lst, cp; |
|
|
va_start(lst, fmt); |
va_start(lst, fmt); |
|
va_copy(cp, lst); |
vfprintf(lf, fmt, lst); |
vfprintf(lf, fmt, lst); |
vsyslog(LOG_ERR, fmt, lst); |
|
va_end(lst); |
va_end(lst); |
|
fprintf(lf, "\n"); |
|
vsyslog(LOG_ERR, fmt, cp); |
|
va_end(cp); |
} |
} |
|
|
static void |
static void |
Line 47 initProg()
|
Line 53 initProg()
|
proc.proc_prio = getpriority(PRIO_PROCESS, 0); |
proc.proc_prio = getpriority(PRIO_PROCESS, 0); |
getcwd(proc.proc_dir, sizeof proc.proc_dir); |
getcwd(proc.proc_dir, sizeof proc.proc_dir); |
|
|
lf = stdout; | lf = fopen(DEFAULT_LOG, "a"); |
| if (!lf) |
| lf = stdout; |
|
|
openlog(PACKAGE_NAME, LOG_CONS | LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_USER); |
openlog(PACKAGE_NAME, LOG_CONS | LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_USER); |
} |
} |
Line 237 Run(char **argv)
|
Line 245 Run(char **argv)
|
return -1; |
return -1; |
} |
} |
|
|
Log(1, "UID:GID=%d:%d Prio=%d Class=%s Name=%s Dir=%s Cmd=%s\n", proc.proc_uid, proc.proc_gid, | Log(0, "UID:GID=%d:%d Prio=%d Class=%s Name=%s Dir=%s Cmd=%s", proc.proc_uid, proc.proc_gid, |
proc.proc_prio, proc.proc_class, proc.proc_name, proc.proc_dir, proc.proc_cmd); |
proc.proc_prio, proc.proc_class, proc.proc_name, proc.proc_dir, proc.proc_cmd); |
|
|
if (3 <= Verbose) { |
if (3 <= Verbose) { |
Line 246 Run(char **argv)
|
Line 254 Run(char **argv)
|
Log(3, "args: %s", *el); |
Log(3, "args: %s", *el); |
} |
} |
|
|
|
fflush(lf); |
|
|
execve(cmd, args, environ); |
execve(cmd, args, environ); |
if (args) |
if (args) |
free(args); |
free(args); |
Line 257 Run(char **argv)
|
Line 267 Run(char **argv)
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
char ch, *str, szCfg[MAXPATHLEN], szLog[MAXPATHLEN], flg = 0; | char ch, *str, szCfg[MAXPATHLEN], flg = 0; |
struct passwd *pass; |
struct passwd *pass; |
struct group *grp; |
struct group *grp; |
FILE *f; |
FILE *f; |
|
|
initProg(); |
initProg(); |
strlcpy(szCfg, DEFAULT_CONFIG, sizeof szCfg); |
strlcpy(szCfg, DEFAULT_CONFIG, sizeof szCfg); |
strlcpy(szLog, DEFAULT_LOG, sizeof szLog); |
|
|
|
while ((ch = getopt(argc, argv, "hvc:u:g:p:d:l:")) != -1) |
while ((ch = getopt(argc, argv, "hvc:u:g:p:d:l:")) != -1) |
switch (ch) { |
switch (ch) { |
case 'l': |
case 'l': |
strlcpy(szLog, optarg, sizeof szLog); | f = fopen(optarg, "a"); |
f = fopen(szLog, "a+"); | |
if (!f) { |
if (!f) { |
Err("Error:: logfile #%d - %s", errno, strerror(errno)); |
Err("Error:: logfile #%d - %s", errno, strerror(errno)); |
return 1; |
return 1; |
} else |
} else |
if (flg & 16 && fileno(lf) > 2) | if (fileno(lf) > 2) |
fclose(lf); |
fclose(lf); |
lf = f; |
lf = f; |
flg |= 16; |
|
break; |
break; |
case 'd': |
case 'd': |
strlcpy(proc.proc_dir, optarg, sizeof proc.proc_dir); |
strlcpy(proc.proc_dir, optarg, sizeof proc.proc_dir); |
Line 317 main(int argc, char **argv)
|
Line 324 main(int argc, char **argv)
|
case 'h': |
case 'h': |
default: |
default: |
Usage(); |
Usage(); |
if (flg & 16) | if (fileno(lf) > 2) |
fclose(lf); |
fclose(lf); |
return 1; |
return 1; |
} |
} |
Line 326 main(int argc, char **argv)
|
Line 333 main(int argc, char **argv)
|
if (!argc) { |
if (!argc) { |
if (!(str = getenv("PATH_TRANSLATED"))) { |
if (!(str = getenv("PATH_TRANSLATED"))) { |
Usage(); |
Usage(); |
if (flg & 16) | if (fileno(lf) > 2) |
fclose(lf); |
fclose(lf); |
return 1; |
return 1; |
} else |
} else |
Line 336 main(int argc, char **argv)
|
Line 343 main(int argc, char **argv)
|
Log(2, "Try to load config %s", szCfg); |
Log(2, "Try to load config %s", szCfg); |
if (LoadConfig(szCfg, &cfg)) { |
if (LoadConfig(szCfg, &cfg)) { |
Err("Error:: can`t load config #%d - %s\n", cfg_GetErrno(), cfg_GetError()); |
Err("Error:: can`t load config #%d - %s\n", cfg_GetErrno(), cfg_GetError()); |
if (flg & 16) | if (fileno(lf) > 2) |
fclose(lf); |
fclose(lf); |
return 2; |
return 2; |
} else |
} else |
if (LoadCfgData(flg) == -1) { |
if (LoadCfgData(flg) == -1) { |
UnloadConfig(&cfg); |
UnloadConfig(&cfg); |
if (flg & 16) | if (fileno(lf) > 2) |
fclose(lf); |
fclose(lf); |
closelog(); |
closelog(); |
return 3; |
return 3; |
Line 350 main(int argc, char **argv)
|
Line 357 main(int argc, char **argv)
|
UnloadConfig(&cfg); |
UnloadConfig(&cfg); |
|
|
if (Run(argv) == -1) { |
if (Run(argv) == -1) { |
if (flg & 16) | if (fileno(lf) > 2) |
fclose(lf); |
fclose(lf); |
closelog(); |
closelog(); |
return 4; |
return 4; |
} |
} |
|
|
if (flg & 16) | if (fileno(lf) > 2) |
fclose(lf); |
fclose(lf); |
closelog(); |
closelog(); |
return 0; |
return 0; |