logo       


[SSI] openssi/sysvinit/src proc.c,NONE,1.1.5.1.2.1 Makefile,1.1.5.1.2.1,1.1: msg#00289

Subject: [SSI] openssi/sysvinit/src proc.c,NONE,1.1.5.1.2.1 Makefile,1.1.5.1.2.1,1.1.5.1.2.2 bootlogd.c,1.1.5.1,1.1.5.1.2.1 halt.c,1.1.5.1.2.1,1.1.5.1.2.2 init.c,1.1.5.1.2.1,1.1.5.1.2.2 init.h,1.1.5.1.2.1,1.1.5.1.2.2 initreq.h,1.1.5.1,1.1.5.1.2.1 killall5.c,1.1.5.1,1.1.5.1.2.1 paths.h,1.1.5.1,1.1.5.1.2.1 shutdown.c,1.1.5.1.2.2,1.1.5.1.2.3
Update of /cvsroot/ssic-linux/openssi/sysvinit/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29525/src

Modified Files:
      Tag: OPENSSI-DEBIAN
        Makefile bootlogd.c halt.c init.c init.h initreq.h killall5.c 
        paths.h shutdown.c 
Added Files:
      Tag: OPENSSI-DEBIAN
        proc.c 
Log Message:
merge with sysvinit-2.85-9


--- NEW FILE: proc.c ---
/*
 * kilall5.c    Kill all processes except processes that have the
 *              same session id, so that the shell that called us
 *              won't be killed. Typically used in shutdown scripts.
 *
 * pidof.c      Tries to get the pid of the process[es] named.
 *
 * Version:     2.85-8 04-Nov-2003 MvS
 *
 * Usage:       killall5 [-][signal]
 *              pidof [-s] [-o omitpid [-o omitpid]] program [program..]
 *
 * Authors:     Miquel van Smoorenburg, miquels@xxxxxxxxxx
 *
 *              Riku Meskanen, <mesrik@xxxxxx>
 *              - return all running pids of given program name
 *              - single shot '-s' option for backwards combatibility
 *              - omit pid '-o' option and %PPID (parent pid metavariable)
 *              - syslog() only if not a connected to controlling terminal
 *              - swapped out programs pids are caught now
 *
 *              This file is part of the sysvinit suite,
 *              Copyright 1991-2003 Miquel van Smoorenburg.
 *
 *              This program is free software; you can redistribute it and/or
 *              modify it under the terms of the GNU General Public License
 *              as published by the Free Software Foundation; either version
 *              2 of the License, or (at your option) any later version.
 */
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <signal.h>
#include <dirent.h>
#include <syslog.h>
#include <getopt.h>
#include <stdarg.h>

char *Version = "@(#)killall5 2.85-8 04-Nov-2003 miquels@xxxxxxxxxx";

/* Info about a process. */
typedef struct proc {
        char *fullname;         /* Name as found out from argv[0] */
        char *basename;         /* Only the part after the last / */
        ino_t ino;              /* Inode number                   */
        dev_t dev;              /* Device it is on                */
        struct proc *next;      /* Pointer to next struct.        */
} PROC;

/* pid list */
typedef struct pidlist {
        pid_t           pid;
        pid_t           sid;
        int             kernel;
        struct pidlist  *next;
} PIDLIST;

int did_sigstop;
char *progname; /* the name of the running program */

#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif
void nsyslog(int pri, char *fmt, ...);

/*
 *      Malloc space, barf if out of memory.
 */
void *xmalloc(int bytes)
{
        void            *p;

        if ((p = malloc(bytes)) == NULL) {
                if (stopped) kill(-1, SIGCONT);
                nsyslog(LOG_ERR, "out of memory");
                exit(1);
        }
        return p;
}

/*
 *      See if the proc filesystem is there. Mount if needed.
 */
int mount_proc(void)
{
        struct stat     st;
        char            *args[] = { "mount", "-t", "proc", "proc", "/proc", 0 };
        pid_t           pid, rc;
        int             did_mount = 0;
        int             wst;

        /* Stat /proc/version to see if /proc is mounted. */
        if (stat("/proc/version", &st) < 0 && errno == ENOENT) {

                /* It's not there, so mount it. */
                if ((pid = fork()) < 0) {
                        nsyslog(LOG_ERR, "cannot fork");
                        exit(1);
                }
                if (pid == 0) {
                        /* Try a few mount binaries. */
                        execv("/sbin/mount", args);
                        execv("/bin/mount", args);

                        /* Okay, I give up. */
                        nsyslog(LOG_ERR, "cannot execute mount");
                        exit(1);
                }
                /* Wait for child. */
                while ((rc = wait(&wst)) != pid)
                        if (rc < 0 && errno == ECHILD)
                                break;
                if (rc != pid || WEXITSTATUS(wst) != 0)
                        nsyslog(LOG_ERR, "mount returned non-zero exit status");

                did_mount = 1;
        }

        /* See if mount succeeded. */
        if (stat("/proc/version", &st) < 0) {
                if (errno == ENOENT)
                        nsyslog(LOG_ERR, "/proc not mounted, failed to mount.");
                else
                        nsyslog(LOG_ERR, "/proc unavailable.");
                exit(1);
        }

        return did_mount;
}

/*
 *      Read the proc filesystem.
 */
PIDLIST *readproc(PROC *filter, int scriptstoo, int except)
{
        DIR             *dir;
        FILE            *fp;
        PROC            *p, *n;
        struct dirent   *d;
        struct stat     st;
        char            path[256];
        char            buf[512];
        char            *s, *q;
        char            *statname;
        unsigned long   startcode, endcode;
        int             pid, sid;
        int             f, c;

        /* Open the /proc directory. */
        if ((dir = opendir("/proc")) == NULL) {
                nsyslog(LOG_ERR, "cannot opendir(/proc)");
                return -1;
        }

        /* Walk through the directory. */
        while ((d = readdir(dir)) != NULL) {

                /* See if this is a process */
                if ((pid = atoi(d->d_name)) == 0) continue;

                startcode = 0;
                endcode = 0;
                sid = 0;
                kernel = 0;
                statname = NULL;

                /* Open the status file. */
                snprintf(path, sizeof(path), "/proc/%s/stat", d->d_name);

                /* Read SID & statname from it. */
                if ((fp = fopen(path, "r")) != NULL) {
                        buf[0] = 0;
                        fgets(buf, sizeof(buf), fp);

                        /* See if name starts with '(' */
                        s = buf;
                        while (*s != ' ') s++;
                        s++;
                        if (*s == '(') {
                                /* Read program name. */
                                q = strrchr(buf, ')');
                                if (q == NULL) {
                                        nsyslog(LOG_ERR,
                                        "can't get program name from %s\n",
                                                path);
                                        continue;
                                }
                                s++;
                        } else {
                                q = s;
                                while (*q != ' ') q++;
                        }
                        *q++ = 0;
                        while (*q == ' ') q++;

                        statname = s;

                        /* Get session, startcode, endcode. */
                        startcode = endcode = 0;
                        if (sscanf(q,   "%*c %*d %*d %d %*d %*d %*u %*u "
                                        "%*u %*u %*u %*u %*u %*d %*d "
                                        "%*d %*d %*d %*d %*u %*u %*d "
                                        "%*u %lu %lu",
                                        &sid, &startcode, &endcode) != 3) {
                                nsyslog(LOG_ERR, "can't read sid from %s\n",
                                        path);
                                continue;
                        }
                        if (startcode == 0 && endcode == 0)
                                kernel = 1;
                        fclose(fp);
                } else {
                        /* Process disappeared.. */
                        free(p);
                        continue;
                }

                /* Now read argv[0] */
                snprintf(path, sizeof(path), "/proc/%s/cmdline", d->d_name);
                if ((fp = fopen(path, "r")) != NULL) {
                        f = 0;
                        while(f < 127 && (c = fgetc(fp)) != EOF && c)
                                buf[f++] = c;
                        buf[f++] = 0;
                        fclose(fp);

                        /* Store the name into malloced memory. */
                        p->fullname = (char *)xmalloc(f);
                        strcpy(p->fullname, buf);

                        /* Get a pointer to the basename. */
                        if ((p->basename = strrchr(p->fullname, '/')) != NULL)
                                p->basename++;
                        else
                                p->basename = p->fullname;
                } else {
                        /* Process disappeared.. */
                        free(p);
                        continue;
                }

                /* Try to stat the executable. */
                snprintf(path, sizeof(path), "/proc/%s/exe", d->d_name);
                if (stat(path, &st) == 0) {
                        p->dev = st.st_dev;
                        p->ino = st.st_ino;
                }

                /* Link it into the list. */
                p->next = plist;
                plist = p;
                p->pid = pid;
        }
        closedir(dir);

        /* Done. */
        return 0;
}

PIDQ *init_pid_q(PIDQ *q)
{
        q->front =  q->next = q->rear = NULL;
        q->proc = NULL;
        return q;
}

int empty_q(PIDQ *q)
{
        return (q->front == NULL);
}

int add_pid_to_q(PIDQ *q, PROC *p)
{
        PIDQ *tmp;

        tmp = (PIDQ *)xmalloc(sizeof(PIDQ));

        tmp->proc = p;
        tmp->next = NULL;

        if (empty_q(q)) {
                q->front = tmp;
                q->rear  = tmp;
        } else {
                q->rear->next = tmp;
                q->rear = tmp;
        }
        return 0;
}

PROC *get_next_from_pid_q(PIDQ *q)
{
        PROC *p;
        PIDQ *tmp = q->front;

        if (!empty_q(q)) {
                p = q->front->proc;
                q->front = tmp->next;
                free(tmp);
                return p;
        }

        return NULL;
}

/* Try to get the process ID of a given process. */
PIDQ *pidof(char *prog)
{
        struct stat st;
        int dostat = 0;
        PROC *p;
        PIDQ *q;
        char *s;
        int foundone = 0;
        int ok = 0;

        /* Try to stat the executable. */
        if (prog[0] == '/' && stat(prog, &st) == 0) dostat++;

        /* Get basename of program. */
        if ((s = strrchr(prog, '/')) == NULL)
                s = prog;
        else
                s++;

        q = (PIDQ *)xmalloc(sizeof(PIDQ));
        q = init_pid_q(q);

        /* First try to find a match based on dev/ino pair. */
        if (dostat) {
                for (p = plist; p; p = p->next) {
                        if (p->dev == st.st_dev && p->ino == st.st_ino) {
                                add_pid_to_q(q, p);
                                foundone++;
                        }
                }
        }

        /* If we didn't find a match based on dev/ino, try the name. */
        if (!foundone) {
                for (p = plist; p; p = p->next) {
                        ok = 0;

                        ok += (strcmp(p->fullname, prog) == 0);
                        ok += (strcmp(p->basename, s) == 0);

                        if (p->fullname[0] == 0 ||
                            strchr(p->fullname, ' ') ||
                            scripts_too)
                                ok += (strcmp(p->statname, s) == 0);

                        if (ok) add_pid_to_q(q, p);
                }
        }

         return q;
}

/* Give usage message and exit. */
void usage(void)
{
        nsyslog(LOG_ERR, "only one argument, a signal number, allowed");
        closelog();
        exit(1);
}

/* write to syslog file if not open terminal */
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif
void nsyslog(int pri, char *fmt, ...)
{
        va_list  args;

        va_start(args, fmt);

        if (ttyname(0) == NULL) {
                vsyslog(pri, fmt, args);
        } else {
                fprintf(stderr, "%s: ",progname);
                vfprintf(stderr, fmt, args);
                fprintf(stderr, "\n");
        }

        va_end(args);
}

#define PIDOF_SINGLE    0x01
#define PIDOF_OMIT      0x02

#define PIDOF_OMITSZ    5

/*
 *      Pidof functionality.
 */
int main_pidof(int argc, char **argv)
{
        PROC *p;
        PIDQ *q;
        int f;
        int first = 1;
        int i,oind, opt, flags = 0;
        pid_t opid[PIDOF_OMITSZ], spid;

        for (oind = PIDOF_OMITSZ-1; oind > 0; oind--)
                opid[oind] = 0;
        opterr = 0;

        while ((opt = getopt(argc,argv,"ho:sx")) != EOF) switch (opt) {
                case '?':
                        nsyslog(LOG_ERR,"invalid options on command line!\n");
                        closelog();
                        exit(1);
                case 'o':
                        if (oind >= PIDOF_OMITSZ -1) {
                                nsyslog(LOG_ERR,"omit pid buffer size %d "
                                        "exceeded!\n", PIDOF_OMITSZ);
                                closelog();
                                exit(1);
                        }
                        if (strcmp("%PPID",optarg) == 0)
                                opid[oind] = getppid();
                        else if ((opid[oind] = atoi(optarg)) < 1) {
                                nsyslog(LOG_ERR,
                                        "illegal omit pid value (%s)!\n",
                                        optarg);
                                closelog();
                                exit(1);
                        }
                        oind++;
                        flags |= PIDOF_OMIT;
                        break;
                case 's':
                        flags |= PIDOF_SINGLE;
                        break;
                case 'x':
                        scripts_too++;
                        break;
                default:
                        /* Nothing */
                        break;
        }
        argc -= optind;
        argv += optind;

        /* Print out process-ID's one by one. */
        readproc();
        for(f = 0; f < argc; f++) {
                if ((q = pidof(argv[f])) != NULL) {
                        spid = 0;
                        while ((p = get_next_from_pid_q(q))) {
                                if (flags & PIDOF_OMIT) {
                                        for (i = 0; i < oind; i++)
                                                if (opid[i] == p->pid)
                                                        break;
                                        /*
                                         *      On a match, continue with
                                         *      the for loop above.
                                         */
                                        if (i < oind)
                                                continue;
                                }
                                if (flags & PIDOF_SINGLE) {
                                        if (spid)
                                                continue;
                                        else
                                                spid = 1;
                                }
                                if (!first)
                                        printf(" ");
                                printf("%d", p->pid);
                                first = 0;
                        }
                }
        }
        printf("\n");
        closelog();
        return(first ? 1 : 0);
}



/* Main for either killall or pidof. */
int main(int argc, char **argv)
{
        PROC *p;
        int pid, sid = -1;
        int sig = SIGKILL;

        /* Get program name. */
        if ((progname = strrchr(argv[0], '/')) == NULL)
                progname = argv[0];
        else
                progname++;

        /* Now connect to syslog. */
        openlog(progname, LOG_CONS|LOG_PID, LOG_DAEMON);

        /* Were we called as 'pidof' ? */
        if (strcmp(progname, "pidof") == 0)
                return main_pidof(argc, argv);

        /* Right, so we are "killall". */
        if (argc > 1) {
                if (argc != 2) usage();
                if (argv[1][0] == '-') (argv[1])++;
                if ((sig = atoi(argv[1])) <= 0 || sig > 31) usage();
        }

        /* First get the /proc filesystem online. */
        mount_proc();

        /*
         *      Ignoring SIGKILL and SIGSTOP do not make sense, but
         *      someday kill(-1, sig) might kill ourself if we don't
         *      do this. This certainly is a valid concern for SIGTERM-
         *      Linux 2.1 might send the calling process the signal too.
         */
        signal(SIGTERM, SIG_IGN);
        signal(SIGSTOP, SIG_IGN);
        signal(SIGKILL, SIG_IGN);

        /* Now stop all processes. */
        kill(-1, SIGSTOP);
        stopped = 1;

        /* Read /proc filesystem */
        if (readproc() < 0) {
                kill(-1, SIGCONT);
                exit(1);
        }

        /* Now kill all processes except our session. */
        sid = getsid();
        for (p = plist; p; p = p->next)
                if (p->pid != pid && p->sid != sid && !p->kernel)
                        kill(p->pid, sig);

        /* And let them continue. */
        kill(-1, SIGCONT);

        /* Done. */
        closelog();

        return 0;
}

Index: Makefile
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/Makefile,v
retrieving revision 1.1.5.1.2.1
retrieving revision 1.1.5.1.2.2
diff -C2 -d -r1.1.5.1.2.1 -r1.1.5.1.2.2
*** Makefile    5 Dec 2003 00:50:44 -0000       1.1.5.1.2.1
--- Makefile    23 Feb 2004 03:02:48 -0000      1.1.5.1.2.2
***************
*** 6,10 ****
  #                        clobber  really cleans up
  #
! # Version:    @(#)Makefile  2.85-5  02-Jul-2003  miquels@xxxxxxxxxx
  #
  
--- 6,10 ----
  #                        clobber  really cleans up
  #
! # Version:    @(#)Makefile  2.85-8  08-Nov-2003  miquels@xxxxxxxxxx
  #
  
***************
*** 67,71 ****
                $(CC) $(LDFLAGS) -o $@ bootlogd.o -lutil
  
! init.o:               init.c init.h set.h reboot.h
                $(CC) -c $(CFLAGS) init.c
  
--- 67,71 ----
                $(CC) $(LDFLAGS) -o $@ bootlogd.o -lutil
  
! init.o:               init.c init.h set.h reboot.h initreq.h
                $(CC) -c $(CFLAGS) init.c
  

Index: bootlogd.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/bootlogd.c,v
retrieving revision 1.1.5.1
retrieving revision 1.1.5.1.2.1
diff -C2 -d -r1.1.5.1 -r1.1.5.1.2.1
*** bootlogd.c  4 Dec 2003 19:39:01 -0000       1.1.5.1
--- bootlogd.c  23 Feb 2004 03:02:48 -0000      1.1.5.1.2.1
***************
*** 4,8 ****
   *            gets written (and fsynced) as soon as possible.
   *
!  * Version:   @(#)bootlogd  2.85  22-Jul-2003  miquels@xxxxxxxxxx
   *
   * Bugs:      Uses openpty(), only available in glibc. Sorry.
--- 4,8 ----
   *            gets written (and fsynced) as soon as possible.
   *
!  * Version:   @(#)bootlogd  2.86pre  04-Nov-2003  miquels@xxxxxxxxxx
   *
   * Bugs:      Uses openpty(), only available in glibc. Sorry.
***************
*** 175,179 ****
        struct consdev  *c;
        int             l, sl, i, fd;
!       char            *p;
  
        sl = strlen(s);
--- 175,179 ----
        struct consdev  *c;
        int             l, sl, i, fd;
!       char            *p, *q;
  
        sl = strlen(s);
***************
*** 187,190 ****
--- 187,191 ----
                for (i = 0; i < 2; i++) {
                        snprintf(res, rlen, i ? c->dev1 : c->dev2, p);
+                       if ((q = strchr(res, ',')) != NULL) *q = 0;
                        if ((fd = open(res, O_RDONLY|O_NONBLOCK)) >= 0) {
                                close(fd);
***************
*** 304,307 ****
--- 305,309 ----
        char            *s;
        int             olen = len;
+       int             dosync = 0;
  
        while (len > 0) {
***************
*** 320,323 ****
--- 322,326 ----
                        case '\n':
                                didnl = 1;
+                               dosync = 1;
                        case '\t':
                        case  32 ... 127:
***************
*** 332,337 ****
                len--;
        }
!       fflush(fp);
!       fdatasync(fileno(fp));
  
        outptr += olen;
--- 335,342 ----
                len--;
        }
!       if (dosync) {
!               fflush(fp);
!               fdatasync(fileno(fp));
!       }
  
        outptr += olen;

Index: halt.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/halt.c,v
retrieving revision 1.1.5.1.2.1
retrieving revision 1.1.5.1.2.2
diff -C2 -d -r1.1.5.1.2.1 -r1.1.5.1.2.2
*** halt.c      5 Dec 2003 00:50:44 -0000       1.1.5.1.2.1
--- halt.c      23 Feb 2004 03:02:48 -0000      1.1.5.1.2.2
***************
*** 23,30 ****
   * Author:    Miquel van Smoorenburg, miquels@xxxxxxxxxx
   *
!  * Version:   2.84,  27-Nov-2001
   *
   *            This file is part of the sysvinit suite,
!  *            Copyright 1991-2001 Miquel van Smoorenburg.
   *
   *            This program is free software; you can redistribute it and/or
--- 23,30 ----
   * Author:    Miquel van Smoorenburg, miquels@xxxxxxxxxx
   *
!  * Version:   2.85,  15-Nov-2003
   *
   *            This file is part of the sysvinit suite,
!  *            Copyright 1991-2003 Miquel van Smoorenburg.
   *
   *            This program is free software; you can redistribute it and/or
***************
*** 49,53 ****
  #include "reboot.h"
  
! char *Version = "@(#)halt  2.84  27-Nov-2001 miquels@xxxxxxxxxx";
  char *progname;
  
--- 49,53 ----
  #include "reboot.h"
  
! char *Version = "@(#)halt  2.85  15-Nov-2003 miquels@xxxxxxxxxx";
  char *progname;
  
***************
*** 261,265 ****
         *      Exit if all we wanted to do was write a wtmp record.
         */
!       if (do_nothing) exit(0);
  
        if (do_sync) {
--- 261,265 ----
         *      Exit if all we wanted to do was write a wtmp record.
         */
!       if (do_nothing && !do_hddown && !do_ifdown) exit(0);
  
        if (do_sync) {
***************
*** 274,277 ****
--- 274,279 ----
                (void)hddown();
  
+       if (do_nothing) exit(0);
+ 
        if (do_reboot) {
                if (do_local)

Index: init.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/init.c,v
retrieving revision 1.1.5.1.2.1
retrieving revision 1.1.5.1.2.2
diff -C2 -d -r1.1.5.1.2.1 -r1.1.5.1.2.2
*** init.c      5 Dec 2003 00:50:44 -0000       1.1.5.1.2.1
--- init.c      23 Feb 2004 03:02:48 -0000      1.1.5.1.2.2
***************
*** 6,10 ****
   *              telinit [0123456SsQqAaBbCc]
   *
!  * Version:   @(#)init.c  2.85  02-Jul-2003  miquels@xxxxxxxxxx
   */
  #ifdef CONFIG_SSI
--- 6,10 ----
   *              telinit [0123456SsQqAaBbCc]
   *
!  * Version:   @(#)init.c  2.85  12-Nov-2003  miquels@xxxxxxxxxx
   */
[...2219 lines suppressed...]
        }
--- 3870,3874 ----
        while ((nstate_table = malloc(sizeof(*nstate_table) * (max_nodes + 1)))
               == NULL) {
!               initlog(L_VB, "out of memory");
                do_sleep(5);
        }
***************
*** 3883,3887 ****
                receive_state(STATE_PIPE);
  
!               myname = strdup(argv[0]);
                argv0 = argv[0];
                maxproclen = 0;
--- 3910,3914 ----
                receive_state(STATE_PIPE);
  
!               myname = istrdup(argv[0]);
                argv0 = argv[0];
                maxproclen = 0;

Index: init.h
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/init.h,v
retrieving revision 1.1.5.1.2.1
retrieving revision 1.1.5.1.2.2
diff -C2 -d -r1.1.5.1.2.1 -r1.1.5.1.2.2
*** init.h      5 Dec 2003 00:50:44 -0000       1.1.5.1.2.1
--- init.h      23 Feb 2004 03:02:48 -0000      1.1.5.1.2.2
***************
*** 37,44 ****
  __attribute__ ((format (printf, 2, 3)))
  #endif
! void log(int loglevel, char *fmt, ...);
  void set_term(int how);
  void print(char *fmt);
  
  /* Actions to be taken by init */
  #define RESPAWN                       1
--- 37,50 ----
  __attribute__ ((format (printf, 2, 3)))
  #endif
! void initlog(int loglevel, char *fmt, ...);
  void set_term(int how);
  void print(char *fmt);
  
+ #if DEBUG
+ #  define INITDBG(level, fmt, args...) initlog(level, fmt, ##args)
+ #else
+ #  define INITDBG(level, fmt, args...)
+ #endif
+ 
  /* Actions to be taken by init */
  #define RESPAWN                       1

Index: initreq.h
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/initreq.h,v
retrieving revision 1.1.5.1
retrieving revision 1.1.5.1.2.1
diff -C2 -d -r1.1.5.1 -r1.1.5.1.2.1
*** initreq.h   4 Dec 2003 19:39:01 -0000       1.1.5.1
--- initreq.h   23 Feb 2004 03:02:48 -0000      1.1.5.1.2.1
***************
*** 1,13 ****
  /*
!  * initreq.h    Interface to let init spawn programs on behalf of
!  *              other programs/daemons.
!  *              Definitions based on sys_term.c from the BSD 4.4
!  *              telnetd source.
   *
!  * Version:     @(#)initreq.h 1.26 23-Apr-2003 MvS
   *
-  * Notes:       Implemented in sysvinit-2.58 and up, but only
-  *            for "telinit". Support for rlogind, telnetd
-  *            and rxvt/xterm might someday follow.
   */
  #ifndef _INITREQ_H
--- 1,14 ----
  /*
!  * initreq.h  Interface to talk to init through /dev/initctl.
   *
!  *            Copyright (C) 1995-2003 Miquel van Smoorenburg
!  *
!  *            This library is free software; you can redistribute it and/or
!  *            modify it under the terms of the GNU Lesser General Public
!  *            License as published by the Free Software Foundation; either
!  *            version 2 of the License, or (at your option) any later version.
!  *
!  * Version:     @(#)initreq.h  1.27  08-Nov-2003 MvS
   *
   */
  #ifndef _INITREQ_H
***************
*** 18,26 ****
  #define INIT_MAGIC 0x03091969
  #define INIT_FIFO  "/dev/initctl"
! #define INIT_CMD_START               0
! #define INIT_CMD_RUNLVL        1
! #define INIT_CMD_POWERFAIL     2
! #define INIT_CMD_POWERFAILNOW  3
! #define INIT_CMD_POWEROK       4
  
  #ifdef MAXHOSTNAMELEN
--- 19,30 ----
  #define INIT_MAGIC 0x03091969
  #define INIT_FIFO  "/dev/initctl"
! #define INIT_CMD_START                0
! #define INIT_CMD_RUNLVL               1
! #define INIT_CMD_POWERFAIL    2
! #define INIT_CMD_POWERFAILNOW 3
! #define INIT_CMD_POWEROK      4
! #define INIT_CMD_BSD          5
! #define INIT_CMD_SETENV               6
! #define INIT_CMD_UNSETENV     7
  
  #ifdef MAXHOSTNAMELEN
***************
*** 30,46 ****
  #endif
  
  struct init_request {
!   int magic;                  /* Magic number                 */
!   int cmd;                    /* What kind of request         */
!   int runlevel;                       /* Runlevel to change to        */
!   int sleeptime;              /* Time between TERM and KILL   */
!   char gen_id[8];             /* Beats me.. telnetd uses "fe" */
!   char tty_id[16];            /* Tty name minus /dev/tty      */
!   char host[INITRQ_HLEN];     /* Hostname                     */
!   char term_type[16];         /* Terminal type                */
!   int signal;                 /* Signal to send               */
!   int pid;                    /* Process to send to           */
!   char exec_name[128];                /* Program to execute           */
!   char reserved[128];         /* For future expansion.        */
  };
  
--- 34,69 ----
  #endif
  
+ /*
+  *    This is what BSD 4.4 uses when talking to init.
+  *    Linux doesn't use this right now.
+  */
+ struct init_request_bsd {
+       char    gen_id[8];              /* Beats me.. telnetd uses "fe" */
+       char    tty_id[16];             /* Tty name minus /dev/tty      */
+       char    host[INITRQ_HLEN];      /* Hostname                     */
+       char    term_type[16];          /* Terminal type                */
+       int     signal;                 /* Signal to send               */
+       int     pid;                    /* Process to send to           */
+       char    exec_name[128];         /* Program to execute           */
+       char    reserved[128];          /* For future expansion.        */
+ };
+ 
+ 
+ /*
+  *    Because of legacy interfaces, "runlevel" and "sleeptime"
+  *    aren't in a seperate struct in the union.
+  *
+  *    The weird sizes are because init expects the whole
+  *    struct to be 384 bytes.
+  */
  struct init_request {
!       int     magic;                  /* Magic number                 */
!       int     cmd;                    /* What kind of request         */
!       int     runlevel;               /* Runlevel to change to        */
!       int     sleeptime;              /* Time between TERM and KILL   */
!       union {
!               struct init_request_bsd bsd;
!               char                    data[368];
!       } i;
  };
  

Index: killall5.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/killall5.c,v
retrieving revision 1.1.5.1
retrieving revision 1.1.5.1.2.1
diff -C2 -d -r1.1.5.1 -r1.1.5.1.2.1
*** killall5.c  4 Dec 2003 19:39:01 -0000       1.1.5.1
--- killall5.c  23 Feb 2004 03:02:48 -0000      1.1.5.1.2.1
***************
*** 6,10 ****
   * pidof.c    Tries to get the pid of the process[es] named.
   *
!  * Version:   2.85-5 02-Jul-2003 MvS
   *
   * Usage:     killall5 [-][signal]
--- 6,10 ----
   * pidof.c    Tries to get the pid of the process[es] named.
   *
!  * Version:   2.85-8 06-Nov-2003 MvS
   *
   * Usage:     killall5 [-][signal]
***************
*** 42,73 ****
  #include <stdarg.h>
  
! char *Version = "@(#)killall5 2.85-5 02-Jul-2003 miquels@xxxxxxxxxx";
  
  /* Info about a process. */
! typedef struct _proc_
! {
!   char *fullname;     /* Name as found out from argv[0] */
!   char *basename;     /* Only the part after the last / */
!   char *statname;     /* the statname without braces    */
!   ino_t ino;          /* Inode number                   */
!   dev_t dev;          /* Device it is on                */
!   pid_t pid;          /* Process ID.                    */
!   int sid;            /* Session ID.                    */
!   struct _proc_ *next;        /* Pointer to next struct.        */
  } PROC;
  
  /* pid queue */
! typedef struct _pidq_ {
!   struct _pidq_ *front;
!   struct _pidq_ *next;
!   struct _pidq_ *rear;
!   PROC                *proc;
  } PIDQ;
  
  /* List of processes. */
  PROC *plist;
  
! /* Did we stop a number of processes? */
! int stopped;
  
  int scripts_too = 0;
--- 42,78 ----
  #include <stdarg.h>
  
! char *Version = "@(#)killall5 2.85-8 06-Nov-2003 miquels@xxxxxxxxxx";
  
  /* Info about a process. */
! typedef struct proc {
!       char *fullname;         /* Name as found out from argv[0] */
!       char *basename;         /* Only the part after the last / */
!       char *statname;         /* the statname without braces    */
!       ino_t ino;              /* Inode number                   */
!       dev_t dev;              /* Device it is on                */
!       pid_t pid;              /* Process ID.                    */
!       int sid;                /* Session ID.                    */
!       int kernel;             /* Kernel thread or zombie.       */
!       struct proc *next;      /* Pointer to next struct.        */
  } PROC;
  
  /* pid queue */
! 
! typedef struct pidq {
!       PROC            *proc;
!       struct pidq     *next;
  } PIDQ;
  
+ typedef struct {
+       PIDQ            *head;
+       PIDQ            *tail;
+       PIDQ            *next;
+ } PIDQ_HEAD;
+ 
  /* List of processes. */
  PROC *plist;
  
! /* Did we stop all processes ? */
! int sent_sigstop;
  
  int scripts_too = 0;
***************
*** 87,91 ****
  
        if ((p = malloc(bytes)) == NULL) {
!               if (stopped) kill(-1, SIGCONT);
                nsyslog(LOG_ERR, "out of memory");
                exit(1);
--- 92,96 ----
  
        if ((p = malloc(bytes)) == NULL) {
!               if (sent_sigstop) kill(-1, SIGCONT);
                nsyslog(LOG_ERR, "out of memory");
                exit(1);
***************
*** 99,107 ****
  int mount_proc(void)
  {
!       struct stat st;
!       pid_t pid, rc;
!       int wst;
!       char *args[] = { "mount", "-t", "proc", "none", "/proc", NULL };
!       int did_mount = 0;
  
        /* Stat /proc/version to see if /proc is mounted. */
--- 104,112 ----
  int mount_proc(void)
  {
!       struct stat     st;
!       char            *args[] = { "mount", "-t", "proc", "proc", "/proc", 0 };
!       pid_t           pid, rc;
!       int             wst;
!       int             did_mount = 0;
  
        /* Stat /proc/version to see if /proc is mounted. */
***************
*** 149,162 ****
  int readproc()
  {
!       DIR *dir;
!       struct dirent *d;
!       char path[256];
!       char buf[256];
!       char *s, *q;
!       FILE *fp;
!       int pid, f;
!       PROC *p, *n;
!       struct stat st;
!       int c;
  
        /* Open the /proc directory. */
--- 154,168 ----
  int readproc()
  {
!       DIR             *dir;
!       FILE            *fp;
!       PROC            *p, *n;
!       struct dirent   *d;
!       struct stat     st;
!       char            path[256];
!       char            buf[256];
!       char            *s, *q;
!       unsigned long   startcode, endcode;
!       int             pid, f;
!       int             c;
  
        /* Open the /proc directory. */
***************
*** 191,195 ****
                if ((fp = fopen(path, "r")) != NULL) {
                        buf[0] = 0;
!                       fgets(buf, 256, fp);
  
                        /* See if name starts with '(' */
--- 197,201 ----
                if ((fp = fopen(path, "r")) != NULL) {
                        buf[0] = 0;
!                       fgets(buf, sizeof(buf), fp);
  
                        /* See if name starts with '(' */
***************
*** 218,223 ****
                        strcpy(p->statname, s);
  
!                       /* This could be replaced by getsid(pid) */
!                       if (sscanf(q, "%*c %*d %*d %d", &p->sid) != 1) {
                                p->sid = 0;
                                nsyslog(LOG_ERR, "can't read sid from %s\n",
--- 224,234 ----
                        strcpy(p->statname, s);
  
!                       /* Get session, startcode, endcode. */
!                       startcode = endcode = 0;
!                       if (sscanf(q,   "%*c %*d %*d %d %*d %*d %*u %*u "
!                                       "%*u %*u %*u %*u %*u %*d %*d "
!                                       "%*d %*d %*d %*d %*u %*u %*d "
!                                       "%*u %lu %lu",
!                                       &p->sid, &startcode, &endcode) != 3) {
                                p->sid = 0;
                                nsyslog(LOG_ERR, "can't read sid from %s\n",
***************
*** 226,229 ****
--- 237,242 ----
                                continue;
                        }
+                       if (startcode == 0 && endcode == 0)
+                               p->kernel = 1;
                        fclose(fp);
                } else {
***************
*** 237,241 ****
                if ((fp = fopen(path, "r")) != NULL) {
                        f = 0;
!                       while(f < 127 && (c = fgetc(fp)) != EOF && c)
                                buf[f++] = c;
                        buf[f++] = 0;
--- 250,254 ----
                if ((fp = fopen(path, "r")) != NULL) {
                        f = 0;
!                       while(f < sizeof(buf)-1 && (c = fgetc(fp)) != EOF && c)
                                buf[f++] = c;
                        buf[f++] = 0;
***************
*** 275,291 ****
  }
  
! PIDQ *init_pid_q(PIDQ *q)
  {
!       q->front =  q->next = q->rear = NULL;
!       q->proc = NULL;
        return q;
  }
  
! int empty_q(PIDQ *q)
  {
!       return (q->front == NULL);
  }
  
! int add_pid_to_q(PIDQ *q, PROC *p)
  {
        PIDQ *tmp;
--- 288,303 ----
  }
  
! PIDQ_HEAD *init_pid_q(PIDQ_HEAD *q)
  {
!       q->head =  q->next = q->tail = NULL;
        return q;
  }
  
! int empty_q(PIDQ_HEAD *q)
  {
!       return (q->head == NULL);
  }
  
! int add_pid_to_q(PIDQ_HEAD *q, PROC *p)
  {
        PIDQ *tmp;
***************
*** 297,317 ****
  
        if (empty_q(q)) {
!               q->front = tmp;
!               q->rear  = tmp;
        } else {
!               q->rear->next = tmp;
!               q->rear = tmp;
        }
        return 0;
  }
  
! PROC *get_next_from_pid_q(PIDQ *q)
  {
!       PROC *p;
!       PIDQ *tmp = q->front;
  
        if (!empty_q(q)) {
!               p = q->front->proc;
!               q->front = tmp->next;
                free(tmp);
                return p;
--- 309,329 ----
  
        if (empty_q(q)) {
!               q->head = tmp;
!               q->tail  = tmp;
        } else {
!               q->tail->next = tmp;
!               q->tail = tmp;
        }
        return 0;
  }
  
! PROC *get_next_from_pid_q(PIDQ_HEAD *q)
  {
!       PROC            *p;
!       PIDQ            *tmp = q->head;
  
        if (!empty_q(q)) {
!               p = q->head->proc;
!               q->head = tmp->next;
                free(tmp);
                return p;
***************
*** 322,334 ****
  
  /* Try to get the process ID of a given process. */
! PIDQ *pidof(char *prog)
  {
!       struct stat st;
!       int dostat = 0;
!       PROC *p;
!       PIDQ *q;
!       char *s;
!       int foundone = 0;
!       int ok = 0;
  
        /* Try to stat the executable. */
--- 334,346 ----
  
  /* Try to get the process ID of a given process. */
! PIDQ_HEAD *pidof(char *prog)
  {
!       PROC            *p;
!       PIDQ_HEAD       *q;
!       struct stat     st;
!       char            *s;
!       int             dostat = 0;
!       int             foundone = 0;
!       int             ok = 0;
  
        /* Try to stat the executable. */
***************
*** 341,345 ****
                s++;
  
!       q = (PIDQ *)xmalloc(sizeof(PIDQ));
        q = init_pid_q(q);
  
--- 353,357 ----
                s++;
  
!       q = (PIDQ_HEAD *)xmalloc(sizeof(PIDQ_HEAD));
        q = init_pid_q(q);
  
***************
*** 413,422 ****
  int main_pidof(int argc, char **argv)
  {
!       PROC *p;
!       PIDQ *q;
!       int f;
!       int first = 1;
!       int i,oind, opt, flags = 0;
!       pid_t opid[PIDOF_OMITSZ], spid;
  
        for (oind = PIDOF_OMITSZ-1; oind > 0; oind--)
--- 425,434 ----
  int main_pidof(int argc, char **argv)
  {
!       PIDQ_HEAD       *q;
!       PROC            *p;
!       pid_t           opid[PIDOF_OMITSZ], spid;
!       int             f;
!       int             first = 1;
!       int             i, oind, opt, flags = 0;
  
        for (oind = PIDOF_OMITSZ-1; oind > 0; oind--)
***************
*** 501,507 ****
  int main(int argc, char **argv)
  {
!       PROC *p;
!       int pid, sid = -1;
!       int sig = SIGKILL;
  
        /* Get program name. */
--- 513,519 ----
  int main(int argc, char **argv)
  {
!       PROC            *p;
!       int             pid, sid = -1;
!       int             sig = SIGKILL;
  
        /* Get program name. */
***************
*** 540,546 ****
        /* Now stop all processes. */
        kill(-1, SIGSTOP);
!       stopped = 1;
  
!       /* Find out our own 'sid'. */
        if (readproc() < 0) {
                kill(-1, SIGCONT);
--- 552,558 ----
        /* Now stop all processes. */
        kill(-1, SIGSTOP);
!       sent_sigstop = 1;
  
!       /* Read /proc filesystem */
        if (readproc() < 0) {
                kill(-1, SIGCONT);
***************
*** 548,561 ****
        }
  
-       pid = getpid();
-       for (p = plist; p; p = p->next)
-               if (p->pid == pid) {
-                       sid = p->sid;
-                       break;
-               }
- 
        /* Now kill all processes except our session. */
        for (p = plist; p; p = p->next)
!               if (p->pid != pid && p->sid != sid)
                        kill(p->pid, sig);
  
--- 560,568 ----
        }
  
        /* Now kill all processes except our session. */
+       sid = (int)getsid(0);
+       pid = (int)getpid();
        for (p = plist; p; p = p->next)
!               if (p->pid != pid && p->sid != sid && !p->kernel)
                        kill(p->pid, sig);
  

Index: paths.h
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/paths.h,v
retrieving revision 1.1.5.1
retrieving revision 1.1.5.1.2.1
diff -C2 -d -r1.1.5.1 -r1.1.5.1.2.1
*** paths.h     14 Apr 2003 11:37:01 -0000      1.1.5.1
--- paths.h     23 Feb 2004 03:02:48 -0000      1.1.5.1.2.1
***************
*** 2,6 ****
   * paths.h    Paths of files that init and related utilities need.
   *
!  * Version:   @(#) paths.h 2.84 27-Nov-2001
   *
   * Author:    Miquel van Smoorenburg, <miquels@xxxxxxxxxx>
--- 2,6 ----
   * paths.h    Paths of files that init and related utilities need.
   *
!  * Version:   @(#) paths.h 2.85-8 05-Nov-2003
   *
   * Author:    Miquel van Smoorenburg, <miquels@xxxxxxxxxx>
***************
*** 25,28 ****
--- 25,29 ----
  #define SDPID         "/var/run/shutdown.pid" /* PID of shutdown program */
  #define SHELL         "/bin/sh"               /* Default shell */
+ #define SULOGIN               "/sbin/sulogin"         /* Sulogin */
  #define INITSCRIPT    "/etc/initscript"       /* Initscript. */
  #define PWRSTAT               "/etc/powerstatus"      /* COMPAT: SIGPWR 
reason (OK/BAD) */

Index: shutdown.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/sysvinit/src/Attic/shutdown.c,v
retrieving revision 1.1.5.1.2.2
retrieving revision 1.1.5.1.2.3
diff -C2 -d -r1.1.5.1.2.2 -r1.1.5.1.2.3
*** shutdown.c  12 Dec 2003 03:12:32 -0000      1.1.5.1.2.2
--- shutdown.c  23 Feb 2004 03:02:48 -0000      1.1.5.1.2.3
***************
*** 14,18 ****
   * Author:    Miquel van Smoorenburg, miquels@xxxxxxxxxx
   *
!  * Version:   @(#)shutdown  2.85-5  02-Jul-2003  miquels@xxxxxxxxxx
   *
   *            This file is part of the sysvinit suite,
--- 14,18 ----
   * Author:    Miquel van Smoorenburg, miquels@xxxxxxxxxx
   *
!  * Version:   @(#)shutdown  2.85-8  19-Dec-2003  miquels@xxxxxxxxxx
   *
[...1282 lines suppressed...]
!               if (wt < 0) wt += 1440;
!       }
!       /* Shutdown NOW if time == 0 */
!       if (wt == 0) shutdown(halttype);
  
!       /* Give warnings on regular intervals and finally shutdown. */
!       if (wt < 15 && !needwarning(wt)) warn(wt, systemstr);
!       while(wt) {
!               if (wt <= 5 && !didnolog) {
!                       donologin(wt);
!                       didnolog++;
!               }
!               if (needwarning(wt)) warn(wt, systemstr);
!               hardsleep(60);
!               wt--;
        }
!       shutdown(halttype);
! 
!       return 0; /* Never happens */
  }



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click


Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe