#include "gw-config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/termios.h>
#include <fcntl.h>
Go to the source code of this file.
◆ _STRUCTURED_PROC
      
        
          | #define _STRUCTURED_PROC   1 | 
        
      
 
 
◆ badusage()
  
  
      
        
          | static void badusage  | 
          ( | 
          const char *  | 
          msg | ) | 
           | 
         
       
   | 
  
static   | 
  
 
 
◆ check()
  
  
      
        
          | static void check  | 
          ( | 
          int  | 
          pid | ) | 
           | 
         
       
   | 
  
static   | 
  
 
 
◆ do_help()
  
  
      
        
          | static void do_help  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
static   | 
  
 
Definition at line 244 of file start-stop-daemon.c.
Referenced by parse_options().
  252 start-stop-daemon for Debian GNU/Linux - small and fast C version written by\n\   253 Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, public domain.\n"   257   start-stop-daemon -S|--start options ... -- arguments ...\n\   258   start-stop-daemon -K|--stop options ...\n\   259   start-stop-daemon -H|--help\n\   260   start-stop-daemon -V|--version\n\   262 Options (at least one of --exec|--pidfile|--user is required):\n\   263   -x|--exec <executable>        program to start/check if it is running\n\   264   -p|--pidfile <pid-file>       pid file to check\n\   265   -c|--chuid <name|uid[:group|gid]>\n\   266         change to this user/group before starting process\n\   267   -u|--user <username>|<uid>    stop processes owned by this user\n\   268   -n|--name <process-name>      stop processes with this name\n\   269   -s|--signal <signal>          signal to send (default TERM)\n\   270   -a|--startas <pathname>       program to start (default is <executable>)\n\   271   -b|--background               force the process to detach\n\   272   -m|--make-pidfile             create the pidfile before starting\n\   273   -t|--test                     test mode, don't do anything\n\   274   -o|--oknodo                   exit status 0 (not 1) if nothing done\n\   275   -q|--quiet                    be more quiet\n\   276   -v|--verbose                  be more verbose\n\   278 Exit status:  0 = done  1 = nothing done (=> 0 if --oknodo)  2 = trouble\n");
   283 start-stop-daemon for Debian GNU/Linux - small and fast C version written by\n\   284 Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, public domain.\n"   288   start-stop-daemon -S options ... -- arguments ...\n\   289   start-stop-daemon -K options ...\n\   290   start-stop-daemon -H\n\   291   start-stop-daemon -V\n\   293 Options (at least one of --exec|--pidfile|--user is required):\n\   294   -x <executable>               program to start/check if it is running\n\   295   -p <pid-file>                 pid file to check\n\   296   -c <name|uid[:group|gid]>     change to this user/group before starting process\n\   297   -u <username>|<uid>           stop processes owned by this user\n\   298   -n <process-name>             stop processes with this name\n\   299   -s <signal>                   signal to send (default TERM)\n\   300   -a <pathname>                 program to start (default is <executable>)\n\   301   -b                            force the process to detach\n\   302   -m                            create the pidfile before starting\n\   303   -t                            test mode, don't do anything\n\   304   -o                            exit status 0 (not 1) if nothing done\n\   306   -v                            be more verbose\n\   308 Exit status:  0 = done  1 = nothing done (=> 0 if -o)  2 = trouble\n");
  
 
 
◆ do_pidfile()
  
  
      
        
          | static void do_pidfile  | 
          ( | 
          const char *  | 
          name | ) | 
           | 
         
       
   | 
  
static   | 
  
 
 
◆ do_stop()
  
  
      
        
          | static int do_stop  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
static   | 
  
 
Definition at line 761 of file start-stop-daemon.c.
References cmdname, execname, exitnodo, fatal(), found, killed, pid_list::next, pid_list::pid, pidfile, progname, push(), quietmode, signal_nr, testmode, and userspec.
Referenced by main().
  772         sprintf(what, 
"process in pidfile `%s'", 
pidfile);
   774         sprintf(what, 
"process(es) owned by `%s'", 
userspec);
   776         fatal(
"internal error, please report");
   780             printf(
"No %s found running; none killed.\n", what);
   785             printf(
"Would send signal %d to %d.\n",
   790             printf(
"%s: warning: failed to kill %d: %s\n",
   796         printf(
"Stopped %s (pid", what);
   798             printf(
" %d", p->
pid);
 static const char * progname
 
static const char * pidfile
 
static void push(struct pid_list **list, int pid)
 
static struct pid_list * found
 
static struct pid_list * killed
 
static const char * cmdname
 
static const char * userspec
 
static void fatal(const char *format,...)
 
 
 
 
◆ fatal()
  
  
      
        
          | static void fatal  | 
          ( | 
          const char *  | 
          format,  | 
         
        
           | 
           | 
            | 
          ...  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
static   | 
  
 
 
◆ main()
      
        
          | int main  | 
          ( | 
          int  | 
          argc,  | 
        
        
           | 
           | 
          char **  | 
          argv  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Definition at line 806 of file start-stop-daemon.c.
References background, changegroup, changeroot, changeuser, do_pidfile(), do_stop(), exec_stat, execname, exitnodo, fatal(), found, mpidfile, optind, parse_options(), pidfile, progname, quietmode, runas_gid, runas_uid, startas, stop, testmode, user_id, and userspec.
  853                 printf(
"%d pids were not killed\n", i);
   861             printf(
"%s already running.\n", 
execname);
   865         printf(
"Would start %s ", 
startas);
   867             printf(
"%s ", *argv++);
   881         printf(
"Starting %s...\n", 
startas);
   901             printf(
"Detatching to start %s...", 
startas);
   904             fatal(
"Unable to fork.\n");
   913         for (i=getdtablesize()-1; i>=0; --i) close(i);
   915         fd = open(
"/dev/tty", O_RDWR);
   916         ioctl(fd, TIOCNOTTY, 0);
   930         fd=open(
"/dev/null", O_RDWR); 
   935         FILE *pidf = fopen(
pidfile, 
"w");
   936         pid_t pidt = getpid();
   938             fatal(
"Unable to open pidfile `%s' for writing: %s", 
pidfile,
   940         fprintf(pidf, 
"%d\n", (
int)pidt);
   944     fatal(
"Unable to start %s: %s", 
startas, strerror(errno));
 
static char * changegroup
 
static struct stat exec_stat
 
static const char * progname
 
static const char * pidfile
 
static void do_pidfile(const char *name)
 
static struct pid_list * found
 
static void parse_options(int argc, char *const *argv)
 
static const char * userspec
 
static void fatal(const char *format,...)
 
 
 
 
◆ parse_options()
  
  
      
        
          | static void parse_options  | 
          ( | 
          int  | 
          argc,  | 
         
        
           | 
           | 
          char *const *  | 
          argv  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
static   | 
  
 
Definition at line 369 of file start-stop-daemon.c.
References background, badusage(), changegroup, changeroot, changeuser, cmdname, do_help(), execname, exitnodo, getopt(), mpidfile, optarg, option, parse_signal(), pidfile, quietmode, signal_nr, signal_str, start, startas, stop, strdup, testmode, and userspec.
Referenced by main().
  373     static struct option longopts[] = {
   374         { 
"help",     0, NULL, 
'H'},
   375         { 
"stop",     0, NULL, 
'K'},
   376         { 
"start",    0, NULL, 
'S'},
   377         { 
"version",      0, NULL, 
'V'},
   378         { 
"startas",      1, NULL, 
'a'},
   379         { 
"name",     1, NULL, 
'n'},
   380         { 
"oknodo",   0, NULL, 
'o'},
   381         { 
"pidfile",      1, NULL, 
'p'},
   382         { 
"quiet",    0, NULL, 
'q'},
   383         { 
"signal",   1, NULL, 
's'},
   384         { 
"test",     0, NULL, 
't'},
   385         { 
"user",     1, NULL, 
'u'},
   386         { 
"chroot",   1, NULL, 
'r'},
   387         { 
"verbose",      0, NULL, 
'v'},
   388         { 
"exec",     1, NULL, 
'x'},
   389         { 
"chuid",    1, NULL, 
'c'},
   390         { 
"background",   0, NULL, 
'b'},
   391         { 
"make-pidfile", 0, NULL, 
'm'},
   399         c = getopt_long(argc, argv, 
"HKSVa:n:op:qr:s:tu:vx:c:bm",
   400                 longopts, (
int *) 0);
   402         c = 
getopt(argc, argv, 
"HKSVa:n:op:qr:s:tu:vx:c:bm");
   417             printf(
"start-stop-daemon " GW_VERSION 
"\n");
   473                 badusage (
"--signal takes a numeric argument or name of signal (KILL, INTR, ...)");
   480         badusage(
"need one of --start or --stop");
   482         badusage(
"need one of -S (start) or -K (stop)");
   486         badusage(
"need at least one of --exec, --pidfile or --user");
   492         badusage(
"--start needs --exec or --startas");
   495         badusage(
"--make-pidfile is only relevant with --pidfile");
   498         badusage(
"--background is only relevant with --start");
 
static char * changegroup
 
static const char * signal_str
 
static const char * pidfile
 
static void badusage(const char *msg)
 
int getopt(int argc, char **argv, char *opts)
 
static void do_help(void)
 
static const char * cmdname
 
static int parse_signal(const char *signal_str, int *signal_nr)
 
static const char * userspec
 
 
 
 
◆ parse_signal()
  
  
      
        
          | static int parse_signal  | 
          ( | 
          const char *  | 
          signal_str,  | 
         
        
           | 
           | 
          int *  | 
          signal_nr  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
static   | 
  
 
 
◆ push()
  
  
      
        
          | static void push  | 
          ( | 
          struct pid_list **  | 
          list,  | 
         
        
           | 
           | 
          int  | 
          pid  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
static   | 
  
 
 
◆ xmalloc()
  
  
      
        
          | static void * xmalloc  | 
          ( | 
          int  | 
          size | ) | 
           | 
         
       
   | 
  
static   | 
  
 
 
◆ background
◆ changegroup
◆ changeroot
◆ changeuser
◆ cmdname
  
  
      
        
          | const char* cmdname = NULL | 
         
       
   | 
  
static   | 
  
 
 
◆ exec_stat
◆ execname
◆ exitnodo
◆ found
Definition at line 173 of file start-stop-daemon.c.
Referenced by check(), do_stop(), get_msg_filename(), http_get_header_parameter(), http_something_accepted(), log_reopen(), main(), smsbox_req_sendota(), soap_fetch_xml_data(), soap_map_xml_data(), wait_for_ack(), wap_push_ppg_pushuser_search_ip_from_wildcarded_list(), wsp_cap_get_client_sdu(), wsp_cap_get_data(), wsp_cap_get_method_mor(), wsp_cap_get_push_mor(), and wsp_cap_get_server_sdu().
 
 
◆ killed
◆ mpidfile
◆ pidfile
  
  
      
        
          | const char* pidfile = NULL | 
         
       
   | 
  
static   | 
  
 
 
◆ progname
  
  
      
        
          | const char* progname = "" | 
         
       
   | 
  
static   | 
  
 
 
◆ quietmode
◆ runas_gid
◆ runas_uid
◆ sigcount
◆ siglist
Initial value:= {
    { "ABRT", SIGABRT },
    { "ALRM", SIGALRM },
    { "FPE", SIGFPE },
    { "HUP", SIGHUP },
    { "ILL", SIGILL },
    { "INT", SIGINT },
    { "KILL", SIGKILL },
    { "PIPE", SIGPIPE },
    { "QUIT", SIGQUIT },
    { "SEGV", SIGSEGV },
    { "TERM", SIGTERM },
    { "USR1", SIGUSR1 },
    { "USR2", SIGUSR2 },
    { "CHLD", SIGCHLD },
    { "CONT", SIGCONT },
    { "STOP", SIGSTOP },
    { "TSTP", SIGTSTP },
    { "TTIN", SIGTTIN },
    { "TTOU", SIGTTOU }
}
 
Definition at line 333 of file start-stop-daemon.c.
Referenced by parse_signal().
 
 
◆ signal_nr
◆ signal_str
  
  
      
        
          | const char* signal_str = NULL | 
         
       
   | 
  
static   | 
  
 
 
◆ start
Definition at line 142 of file start-stop-daemon.c.
Referenced by at2_scan_for_telnet_escapes(), cid_matches(), compare_octstr_sequence(), eat_string_parm(), get_start_param(), get_variable(), http_header_add_element(), http_header_quoted_string_len(), http_header_split_value(), main(), meta_data_unpack(), mime_multipart_start_elem(), mime_something_to_entity(), normalize_number(), octstr_append_uintvar(), octstr_isnum(), octstr_split_words(), octstr_strip_blanks(), octstr_strip_char(), octstr_strip_crlfs(), octstr_strip_nonalphanums(), pack_parameter(), pack_warning(), parse_cgivars(), parse_options(), parse_st_octet_string(), parse_variable(), pass_field_name(), pass_field_value(), read_messages_from_bearerbox(), smsc2_find(), soap_format_xml(), split_headers(), string_table_sort_list(), wait_for_ack(), and ws_vfprintf().
 
 
◆ startas
◆ stop
◆ testmode
◆ user_id
◆ userspec
  
  
      
        
          | const char* userspec = NULL | 
         
       
   | 
  
static   |