Annotation of researchv10no/cmd/asd++/cdaemon.c, revision 1.1.1.1

1.1       root        1: #include "decl.h"
                      2: 
                      3: extern "C" {
                      4:        extern int setlogname (char*);
                      5: }
                      6: 
                      7: main()
                      8: {
                      9:        Path_list dirs = dircontents (spooldir);
                     10:        Path_list_iterator pli (dirs);
                     11:        Path p;
                     12:        while (pli.nextX (p)) {
                     13:                Path dir = spooldir & p;
                     14: 
                     15:                /*
                     16:                 * Try to remove the directory.  If we fail,
                     17:                 * that means it isn't empty, so there's work to do.
                     18:                 */
                     19:                if (rmdir (dir) < 0) {
                     20:                        /* If the lock file exists, leave it alone */
                     21:                        if (access (dir & "lock", 0) < 0) {
                     22:                                struct stat sb;
                     23:                                int pid = fork();
                     24:                                int rc;
                     25:                                switch (pid) {
                     26:                                case -1:                // better luck next time
                     27:                                        break;
                     28: 
                     29:                                case 0:                 // child
                     30:                                        if (stat (dir, &sb) >= 0) {
                     31:                                                charstr ln = String(p);
                     32:                                                charstr d = String(Path(etcdir) & "udaemon");
                     33:                                                setlogname (ln);
                     34:                                                setgid (sb.st_gid);
                     35:                                                setuid (sb.st_uid);
                     36:                                                execl (d, "udaemon", (char*) 0);
                     37:                                        }
                     38:                                        exit (1);
                     39: 
                     40:                                default:                // parent
                     41:                                        while ((rc = wait (0)) != -1 &&
                     42:                                            rc != pid)
                     43:                                                ;
                     44:                                        break;
                     45:                                }
                     46:                        }
                     47:                }
                     48:        }
                     49:        return 0;
                     50: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.