diff --git a/envdir.c b/envdir.c index f02e739..dddd3c9 100644 --- a/envdir.c +++ b/envdir.c @@ -71,14 +71,14 @@ int main(int argc,const char *const *argv) if (sa.len) { sa.len = byte_chr(sa.s,sa.len,'\n'); while (sa.len) { - if (sa.s[sa.len - 1] != ' ') - if (sa.s[sa.len - 1] != '\t') - break; - --sa.len; + if (sa.s[sa.len - 1] != ' ') + if (sa.s[sa.len - 1] != '\t') + break; + --sa.len; } for (i = 0;i < sa.len;++i) - if (!sa.s[i]) - sa.s[i] = '\n'; + if (!sa.s[i]) + sa.s[i] = '\n'; if (!stralloc_0(&sa)) nomem(); if (!pathexec_env(saname.s,sa.s)) nomem(); } diff --git a/envini.c b/envini.c index 3054e90..5d68c1f 100644 --- a/envini.c +++ b/envini.c @@ -47,28 +47,28 @@ static void parse(void) ++start; if (end > start) { if (sa.s[start] == '[' && sa.s[end-1] == ']') { - if (!stralloc_copyb(§ion,sa.s+start+1,end-start-2)) nomem(); - if (!stralloc_append(§ion,'_')) nomem(); + if (!stralloc_copyb(§ion,sa.s+start+1,end-start-2)) nomem(); + if (!stralloc_append(§ion,'_')) nomem(); } else if (sa.s[start] == ';') - ; + ; else { - i = start; - while (i < end && sa.s[i] != '=' && !is_space(sa.s[i])) - ++i; - if (!stralloc_copys(&name,prefix)) nomem(); - if (!stralloc_cat(&name,§ion)) nomem(); - if (!stralloc_catb(&name,sa.s+start,i-start)) nomem(); - if (!stralloc_0(&name)) nomem(); - while (i < end && is_space(sa.s[i])) - ++i; - if (i >= end || sa.s[i++] != '=') - continue; /* Ignore misformatted lines */ - while (i < end && is_space(sa.s[i])) - ++i; - if (!stralloc_copyb(&value,sa.s+i,end-i)) nomem(); - if (!stralloc_0(&value)) nomem(); - if (!pathexec_env(name.s,value.s)) nomem(); + i = start; + while (i < end && sa.s[i] != '=' && !is_space(sa.s[i])) + ++i; + if (!stralloc_copys(&name,prefix)) nomem(); + if (!stralloc_cat(&name,§ion)) nomem(); + if (!stralloc_catb(&name,sa.s+start,i-start)) nomem(); + if (!stralloc_0(&name)) nomem(); + while (i < end && is_space(sa.s[i])) + ++i; + if (i >= end || sa.s[i++] != '=') + continue; /* Ignore misformatted lines */ + while (i < end && is_space(sa.s[i])) + ++i; + if (!stralloc_copyb(&value,sa.s+i,end-i)) nomem(); + if (!stralloc_0(&value)) nomem(); + if (!pathexec_env(name.s,value.s)) nomem(); } } } @@ -81,8 +81,8 @@ int main(int argc,const char *const *argv) while ((opt = getopt(argc,argv,"p:")) != opteof) switch (opt) { - case 'p': prefix = optarg; break; - default: die_usage(); + case 'p': prefix = optarg; break; + default: die_usage(); } argv += optind; diff --git a/installer.c b/installer.c index e579cec..3de6f6a 100644 --- a/installer.c +++ b/installer.c @@ -94,36 +94,36 @@ void doit(stralloc *line) case 'd': if (mkdir(target.s,0700) == -1) if (errno != error_exist) - strerr_die3sys(111,FATAL,"unable to mkdir ",target.s); + strerr_die3sys(111,FATAL,"unable to mkdir ",target.s); break; case 'c': fdin = open_read(name); if (fdin == -1) { - if (opt) - return; - else - strerr_die3sys(111,FATAL,"unable to read ",name); + if (opt) + return; + else + strerr_die3sys(111,FATAL,"unable to read ",name); } buffer_init(&bufin,buffer_unixread,fdin,inbuf,sizeof(inbuf)); fdout = open_trunc(target.s); if (fdout == -1) - strerr_die3sys(111,FATAL,"unable to write ",target.s); + strerr_die3sys(111,FATAL,"unable to write ",target.s); buffer_init(&bufout,buffer_unixwrite,fdout,outbuf,sizeof(outbuf)); switch(buffer_copy(&bufout,&bufin)) { - case -2: - strerr_die3sys(111,FATAL,"unable to read ",name); - case -3: - strerr_die3sys(111,FATAL,"unable to write ",target.s); + case -2: + strerr_die3sys(111,FATAL,"unable to read ",name); + case -3: + strerr_die3sys(111,FATAL,"unable to write ",target.s); } close(fdin); if (buffer_flush(&bufout) == -1) - strerr_die3sys(111,FATAL,"unable to write ",target.s); + strerr_die3sys(111,FATAL,"unable to write ",target.s); if (fsync(fdout) == -1) - strerr_die3sys(111,FATAL,"unable to write ",target.s); + strerr_die3sys(111,FATAL,"unable to write ",target.s); close(fdout); break; diff --git a/multilog.c b/multilog.c index 464bb39..dca386e 100644 --- a/multilog.c +++ b/multilog.c @@ -136,8 +136,8 @@ int filesfit(struct cyclog *d) if (x->d_name[0] == '@') if (str_len(x->d_name) >= 25) if (str_start(x->d_name,fn.s)) { - unlink(x->d_name); - break; + unlink(x->d_name); + break; } } if (errno) { closedir(dir); return -1; } @@ -161,7 +161,7 @@ void finish(struct cyclog *d,const char *file,const char *code) fnlen = fmt_tai64nstamp(fn.s); fn.s[fnlen++] = '.'; do { - fn.s[fnlen++] = *code; + fn.s[fnlen++] = *code; } while (*code++ != 0); if (link(file,fn.s) == 0) break; @@ -419,7 +419,7 @@ void c_init(char **script) else if (script[i][0] == 'w') { code_finished = script[i] + 1; if (!stralloc_ready(&fn,str_len(code_finished)+TIMESTAMP+1)) - strerr_die2sys(111,FATAL,"unable to allocate memory"); + strerr_die2sys(111,FATAL,"unable to allocate memory"); } else if ((script[i][0] == '.') || (script[i][0] == '/')) { d->num = num; @@ -469,7 +469,7 @@ int flushread(int fd,char *buf,int len) if (flagforcerotate) { for (j = 0;j < cnum;++j) if (c[j].bytes > 0) - fullcurrent(&c[j]); + fullcurrent(&c[j]); flagforcerotate = 0; } @@ -524,8 +524,8 @@ void doit(char **script) return; if (flagtimestamp) { linelen = (flagtimestamp == 't') - ? fmt_tai64nstamp(line) - : fmt_accustamp(line); + ? fmt_tai64nstamp(line) + : fmt_accustamp(line); line[linelen++] = ' '; } if (buffer_gets(&ssin,line+linelen,MAXLINE-linelen,'\n',&linelen) < 0) @@ -538,11 +538,11 @@ void doit(char **script) for (i = 0;(action = script[i]) != 0;++i) switch(*action) { case 'F': - match = match_fnmatch; - break; + match = match_fnmatch; + break; case 'S': - match = match_simple; - break; + match = match_simple; + break; case '+': if (!flagselected) if (match(action + 1,line,linelen)) @@ -590,19 +590,19 @@ void doit(char **script) while (linelen == MAXLINE) { linelen = 0; if (buffer_gets(&ssin,line,MAXLINE,'\n',&linelen) < 0) { - flageof = 1; - break; + flageof = 1; + break; } if (linelen == 0) - break; + break; for (j = 0;j < cnum;++j) - if (c[j].flagselected) - buffer_put(&c[j].ss,line,linelen); + if (c[j].flagselected) + buffer_put(&c[j].ss,line,linelen); } for (j = 0;j < cnum;++j) if (c[j].flagselected) { - ch = '\n'; + ch = '\n'; buffer_PUTC(&c[j].ss,ch); } diff --git a/pathexec_env.c b/pathexec_env.c index 2cb101c..0779c75 100644 --- a/pathexec_env.c +++ b/pathexec_env.c @@ -52,14 +52,14 @@ void pathexec(const char *const *argv) if (!plus.s[i]) { split = str_chr(plus.s + j,'='); for (t = 0;t < elen;++t) - if (byte_equal(plus.s + j,split,e[t])) - if (e[t][split] == '=') { - --elen; - e[t] = e[elen]; - break; - } + if (byte_equal(plus.s + j,split,e[t])) + if (e[t][split] == '=') { + --elen; + e[t] = e[elen]; + break; + } if (plus.s[j + split]) - e[elen++] = plus.s + j; + e[elen++] = plus.s + j; j = i + 1; } e[elen] = 0; diff --git a/readproctitle.c b/readproctitle.c index 82fbffd..0203a6c 100644 --- a/readproctitle.c +++ b/readproctitle.c @@ -17,14 +17,14 @@ int main(int argc,char **argv) for (;;) switch(read(0,&ch,1)) { case 1: - if (ch) { - for (i = 4;i < len;++i) buf[i - 1] = buf[i]; - buf[len - 1] = ch; - } - break; + if (ch) { + for (i = 4;i < len;++i) buf[i - 1] = buf[i]; + buf[len - 1] = ch; + } + break; case 0: - _exit(0); + _exit(0); case -1: - if (errno != error_intr) _exit(111); + if (errno != error_intr) _exit(111); } } diff --git a/softlimit.c b/softlimit.c index ea4c5b0..2e17de7 100644 --- a/softlimit.c +++ b/softlimit.c @@ -99,7 +99,7 @@ int main(int argc,const char *const *argv,const char *const *envp) while ((opt = getopt(argc,argv,"a:c:d:f:l:m:o:p:r:s:t:")) != opteof) switch(opt) { case '?': - die_usage(); + die_usage(); case 'a': #ifdef RLIMIT_AS doit(RLIMIT_AS,optarg); @@ -144,7 +144,7 @@ int main(int argc,const char *const *argv,const char *const *envp) #ifdef RLIMIT_AS doit(RLIMIT_AS,optarg); #endif - break; + break; case 'o': #ifdef RLIMIT_NOFILE doit(RLIMIT_NOFILE,optarg); diff --git a/subgetopt.c b/subgetopt.c index 266e72a..85ace96 100644 --- a/subgetopt.c +++ b/subgetopt.c @@ -54,7 +54,7 @@ int sgopt(int argc,const char *const *argv,const char *opts) optproblem = c; return '?'; } - ++optind; + ++optind; } } return c; diff --git a/supervise.c b/supervise.c index 201ab09..485c618 100644 --- a/supervise.c +++ b/supervise.c @@ -121,11 +121,11 @@ static int forkexecve(struct svc *svc,const char *argv[],int fd) sig_uncatch(sig_ttystop); sig_uncatch(sig_cont); if (stat_exists("no-setsid") == 0) - setsid(); /* shouldn't fail; if it does, too bad */ + setsid(); /* shouldn't fail; if it does, too bad */ if (fd >= 0 && logpipe[0] >= 0) { - dup2(logpipe[fd],fd); - close(logpipe[0]); - close(logpipe[1]); + dup2(logpipe[fd],fd); + close(logpipe[0]); + close(logpipe[1]); } execve(argv[0],(char*const*)argv,environ); strerr_die4sys(111,FATAL,"unable to start ",dir,argv[0]+1); @@ -301,32 +301,32 @@ void doit(void) if (!r) break; if ((r == -1) && (errno != error_intr)) break; if (r == svcmain.pid) - svc = &svcmain; + svc = &svcmain; else if (r == svclog.pid) - svc = &svclog; + svc = &svclog; else - continue; + continue; killpid = svc->pid; svc->pid = 0; if (((svc == &svcmain && svc->flagstatus == svstatus_starting) && (wait_crashed(wstat) || wait_exitcode(wstat) != 0)) - || (!wait_crashed(wstat) && wait_exitcode(wstat) == 100)) { - svc->flagwantup = 0; - svc->flagstatus = svstatus_failed; + || (!wait_crashed(wstat) && wait_exitcode(wstat) == 100)) { + svc->flagwantup = 0; + svc->flagstatus = svstatus_failed; } else if (svc == &svcmain && svc->flagstatus == svstatus_starting) { } else if (!svc->flagwant || !svc->flagwantup) - svc->flagstatus = svstatus_stopped; + svc->flagstatus = svstatus_stopped; pidchange(svc, wait_crashed(wstat) ? "killed" : "exit", - wait_crashed(wstat) ? wait_stopsig(wstat) : wait_exitcode(wstat), - killpid); + wait_crashed(wstat) ? wait_stopsig(wstat) : wait_exitcode(wstat), + killpid); firstrun = 0; if ((svc->flagwant && svc->flagwantup) || (svc == &svcmain && svc->flagstatus == svstatus_starting)) { - if (!flagexit) - trystart(svc); + if (!flagexit) + trystart(svc); } else if (svc->flagstatus != svstatus_failed) - trystop(svc); + trystop(svc); break; } @@ -335,89 +335,89 @@ void doit(void) while (read(fdcontrol,&ch,1) == 1) switch(ch) { case '+': - if (killpid > 0) killpid = -killpid; - break; + if (killpid > 0) killpid = -killpid; + break; case '=': - if (killpid < 0) killpid = -killpid; - break; + if (killpid < 0) killpid = -killpid; + break; case 'L': - svc = &svclog; - killpid = svc->pid; - break; + svc = &svclog; + killpid = svc->pid; + break; case 'l': - svc = &svcmain; - killpid = svc->pid; - break; - case 'd': - svc->flagwant = 1; - svc->flagwantup = 0; - if (killpid) - stopsvc(killpid,svc); - else - trystop(svc); - announce(); - break; - case 'u': - if (svc == &svcmain) - firstrun = !svcmain.flagwantup; - svc->flagwant = 1; - svc->flagwantup = 1; - if (!svc->pid) - svc->flagstatus = svstatus_starting; - announce(); - if (!svc->pid) trystart(svc); - break; - case 'o': - svc->flagwant = 0; - announce(); - if (!svc->pid) trystart(svc); - break; - case 'a': - if (killpid) kill(killpid,SIGALRM); - break; - case 'h': - if (killpid) kill(killpid,SIGHUP); - break; - case 'k': - if (killpid) kill(killpid,SIGKILL); - break; - case 't': - if (killpid) kill(killpid,SIGTERM); - break; - case 'i': - if (killpid) kill(killpid,SIGINT); - break; - case 'q': - if (killpid) kill(killpid,SIGQUIT); - break; - case '1': - if (killpid) kill(killpid,SIGUSR1); - break; - case '2': - if (killpid) kill(killpid,SIGUSR2); - break; - case 'w': - if (killpid) kill(killpid,SIGWINCH); - break; - case 'p': - svc->flagpaused = 1; - announce(); - if (killpid) kill(killpid,SIGSTOP); - break; - case 'c': - svc->flagpaused = 0; - announce(); - if (killpid) kill(killpid,SIGCONT); - break; - case 'x': - flagexit = 1; - announce(); - break; + svc = &svcmain; + killpid = svc->pid; + break; + case 'd': + svc->flagwant = 1; + svc->flagwantup = 0; + if (killpid) + stopsvc(killpid,svc); + else + trystop(svc); + announce(); + break; + case 'u': + if (svc == &svcmain) + firstrun = !svcmain.flagwantup; + svc->flagwant = 1; + svc->flagwantup = 1; + if (!svc->pid) + svc->flagstatus = svstatus_starting; + announce(); + if (!svc->pid) trystart(svc); + break; + case 'o': + svc->flagwant = 0; + announce(); + if (!svc->pid) trystart(svc); + break; + case 'a': + if (killpid) kill(killpid,SIGALRM); + break; + case 'h': + if (killpid) kill(killpid,SIGHUP); + break; + case 'k': + if (killpid) kill(killpid,SIGKILL); + break; + case 't': + if (killpid) kill(killpid,SIGTERM); + break; + case 'i': + if (killpid) kill(killpid,SIGINT); + break; + case 'q': + if (killpid) kill(killpid,SIGQUIT); + break; + case '1': + if (killpid) kill(killpid,SIGUSR1); + break; + case '2': + if (killpid) kill(killpid,SIGUSR2); + break; + case 'w': + if (killpid) kill(killpid,SIGWINCH); + break; + case 'p': + svc->flagpaused = 1; + announce(); + if (killpid) kill(killpid,SIGSTOP); + break; + case 'c': + svc->flagpaused = 0; + announce(); + if (killpid) kill(killpid,SIGCONT); + break; + case 'x': + flagexit = 1; + announce(); + break; } if (flagexit - && svcmain.flagstatus == svstatus_stopped - && (svclog.flagstatus == svstatus_running || svclog.flagstatus == svstatus_started)) + && svcmain.flagstatus == svstatus_stopped + && (svclog.flagstatus == svstatus_running || svclog.flagstatus == svstatus_started)) stopsvc(svclog.pid,&svclog); } } diff --git a/svc.c b/svc.c index 79e9397..0063f4e 100644 --- a/svc.c +++ b/svc.c @@ -50,8 +50,7 @@ int main(int argc,const char *const *argv) while ((dir = *argv++) != 0) { if (chdir(dir) == -1) strerr_warn4sys(WARNING,"unable to chdir to ",dir,""); - else if (!svpath_init() - || (fncontrol = svpath_make("/control")) == 0) + else if (!svpath_init() || (fncontrol = svpath_make("/control")) == 0) strerr_warn4sys(WARNING,"unable to setup control path for ",dir,""); else { fd = open_write(fncontrol); diff --git a/svpath.c b/svpath.c index 114d935..631b508 100644 --- a/svpath.c +++ b/svpath.c @@ -19,7 +19,7 @@ int svpath_init(void) return 0; for (ptr = cwd+1; *ptr != 0; ++ptr) if (*ptr == '/') - *ptr = ':'; + *ptr = ':'; if (!stralloc_cats(&svdir, cwd)) return 0; } diff --git a/svscan.c b/svscan.c index edcc46b..70f99b4 100644 --- a/svscan.c +++ b/svscan.c @@ -65,7 +65,7 @@ void start(const char *fn) for (i = 0;i < numx;++i) if (x[i].ino == st.st_ino) if (x[i].dev == st.st_dev) - break; + break; if (i == numx) { if (numx >= SERVICES) { @@ -83,12 +83,12 @@ void start(const char *fn) byte_copy(fnlog,fnlen,fn); byte_copy(fnlog + fnlen,5,"/log"); if (stat(fnlog,&st) == 0) - x[i].flaglog = S_ISDIR(st.st_mode); + x[i].flaglog = S_ISDIR(st.st_mode); else - if (errno != error_noent) { + if (errno != error_noent) { strerr_warn4sys(WARNING,"unable to stat ",fn,"/log"); return; - } + } } if (x[i].flaglog) { @@ -111,18 +111,18 @@ void start(const char *fn) return; case 0: if (x[i].flaglog) - if (fd_move(1,x[i].pi[1]) == -1) + if (fd_move(1,x[i].pi[1]) == -1) + strerr_die3sys(111,WARNING,"unable to set up descriptors for ",fn); + if (i == logx) + if (fd_move(0,logpipe[0]) == -1) strerr_die3sys(111,WARNING,"unable to set up descriptors for ",fn); - if (i == logx) - if (fd_move(0,logpipe[0]) == -1) - strerr_die3sys(111,WARNING,"unable to set up descriptors for ",fn); args[0] = "supervise"; args[1] = fn; args[2] = 0; - pathexec_run(*args,args,(const char*const*)environ); + pathexec_run(*args,args,(const char*const*)environ); strerr_die3sys(111,WARNING,"unable to start supervise ",fn); default: - x[i].pid = child; + x[i].pid = child; all_stopped = 0; } else @@ -140,15 +140,15 @@ void start(const char *fn) case 0: if (fd_move(0,x[i].pi[0]) == -1) strerr_die4sys(111,WARNING,"unable to set up descriptors for ",fn,"/log"); - if (chdir(fn) == -1) + if (chdir(fn) == -1) strerr_die3sys(111,WARNING,"unable to switch to ",fn); args[0] = "supervise"; args[1] = "log"; args[2] = 0; - pathexec_run(*args,args,(const char*const*)environ); + pathexec_run(*args,args,(const char*const*)environ); strerr_die4sys(111,WARNING,"unable to start supervise ",fn,"/log"); default: - x[i].pidlog = child; + x[i].pidlog = child; all_stopped = 0; } else diff --git a/svstat.c b/svstat.c index c2a91b0..f010b7a 100644 --- a/svstat.c +++ b/svstat.c @@ -173,8 +173,8 @@ void doit(const char *dir) if (check_log != 0) { if (r >= 20+18) { if (check_log < 0) { - buffer_puts(&b,"\n"); - buffer_puts(&b,dir); + buffer_puts(&b,"\n"); + buffer_puts(&b,dir); } buffer_puts(&b," log: "); showstatus(status+20,r-20,normallyup); diff --git a/svup.c b/svup.c index 6a78b66..76de1eb 100644 --- a/svup.c +++ b/svup.c @@ -13,7 +13,7 @@ static int checkstatus(const char status[19], int r) /* Check for a PID */ return (status[12] || status[13] || status[14] || status[15]) /* Check for a PID */ || (r > 18 - && (status[18] == svstatus_started || status[18] == svstatus_running)); + && (status[18] == svstatus_started || status[18] == svstatus_running)); } static void die_usage(void) @@ -82,11 +82,11 @@ int main(int argc,const char *const *argv) if (check_log != 0) { if (rd < 20+18) { if (check_log > 0) - _exit(100); + _exit(100); } else if (!checkstatus(status+20,rd-20)) - _exit(100); + _exit(100); } _exit(0); }