Annotation of freem/src/fma_jobs.c, revision 1.1

1.1     ! snw         1: /*
        !             2:  *                            *
        !             3:  *                           * *
        !             4:  *                          *   *
        !             5:  *                     ***************
        !             6:  *                      * *       * *
        !             7:  *                       *  MUMPS  *
        !             8:  *                      * *       * *
        !             9:  *                     ***************
        !            10:  *                          *   *
        !            11:  *                           * *
        !            12:  *                            *
        !            13:  *
        !            14:  *   fma_jobs.c
        !            15:  *    fmadm - jobs
        !            16:  *
        !            17:  *  
        !            18:  *   Author: Serena Willis <jpw@coherent-logic.com>
        !            19:  *    Copyright (C) 1998 MUG Deutschland
        !            20:  *    Copyright (C) 2020 Coherent Logic Development LLC
        !            21:  *
        !            22:  *
        !            23:  *   This file is part of FreeM.
        !            24:  *
        !            25:  *   FreeM is free software: you can redistribute it and/or modify
        !            26:  *   it under the terms of the GNU Affero Public License as published by
        !            27:  *   the Free Software Foundation, either version 3 of the License, or
        !            28:  *   (at your option) any later version.
        !            29:  *
        !            30:  *   FreeM is distributed in the hope that it will be useful,
        !            31:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            32:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            33:  *   GNU Affero Public License for more details.
        !            34:  *
        !            35:  *   You should have received a copy of the GNU Affero Public License
        !            36:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
        !            37:  *
        !            38:  **/
        !            39: 
        !            40: #include <stdio.h>
        !            41: #include <stdlib.h>
        !            42: #include <string.h>
        !            43: #include <dirent.h>
        !            44: #include <stdlib.h>
        !            45: #include <time.h>
        !            46: #include <unistd.h>
        !            47: #include <sys/types.h>
        !            48: #include <sys/stat.h>
        !            49: #include <ctype.h>
        !            50: 
        !            51: #include "fmadm.h"
        !            52: #include "freem.h"
        !            53: #include "jobtab.h"
        !            54: 
        !            55: void get_job_property (char *tbuf, int length, long jobpid, char *property);
        !            56: 
        !            57: int fma_jobs_list (int optc, char **opts)
        !            58: {
        !            59:     printf ("\nFreeM Job Listing\n");
        !            60:     printf (  "-----------------\n\n");
        !            61: 
        !            62:     job_dump ();
        !            63:     
        !            64:     return 0;
        !            65: }
        !            66: 
        !            67: int fma_jobs_remove (int optc, char **opts)
        !            68: {
        !            69:     int i;
        !            70:     pid_t job_pid;
        !            71:     
        !            72:     for (i = fma_base_opt; i < optc; i++) {
        !            73: 
        !            74:         job_pid = atol (opts[i]);
        !            75: 
        !            76:         kill (job_pid, SIGTERM);
        !            77:         
        !            78:     }
        !            79: 
        !            80:     return 0;
        !            81: }
        !            82: 
        !            83: int fma_jobs_examine (int optc, char **opts)
        !            84: {
        !            85:     long pids[FMA_MAXPID];
        !            86: 
        !            87:     register int i;
        !            88:     register int j = 0;
        !            89:     register int pidct = optc - 1;
        !            90: 
        !            91: 
        !            92:     char j_uid[512];
        !            93:     char j_gid[512];
        !            94:     char j_namespace[512];
        !            95:     char j_io[512];
        !            96:     char j_tlevel[512];
        !            97:     char j_routine[512];
        !            98: 
        !            99: 
        !           100:     if (pidct < 1) {
        !           101:         fprintf (stderr, "usage:  fmadm examine job <namespace> pid1 pid2 ...pidN\n");
        !           102:         return 1;
        !           103:     }
        !           104: 
        !           105:     for (i = fma_base_opt; i < optc; i++) {
        !           106:         if (i == FMA_MAXPID) break;
        !           107:         pids[j++] = atol (opts[i]);
        !           108:     }
        !           109: 
        !           110:     printf ("\nFreeM Job Examine\n");
        !           111:     printf ("-----------------\n\n");
        !           112: 
        !           113:     printf ("PIDs:    ");
        !           114: 
        !           115:     for (i = 0; i < pidct; i++) {
        !           116:         printf ("%ld ", pids[i]);
        !           117:     }
        !           118: 
        !           119:     printf ("\n\n");
        !           120: 
        !           121:     /* pid uid gid namespace io tlevel routine */
        !           122:     printf ("%-8s %-8s %-8s %-12s %-30s %-10s %s\n", "PID", "UID", "GID", "NAMESPACE", "$IO", "$TLEVEL", "ROUTINE");
        !           123:     printf ("%-8s %-8s %-8s %-12s %-30s %-10s %s\n", "---", "---", "---", "---------", "---", "-------", "-------");
        !           124: 
        !           125:     for (i = 0; i < pidct; i++) {
        !           126: 
        !           127:         get_job_property (j_uid, 511, pids[i], "USER");
        !           128:         get_job_property (j_gid, 511, pids[i], "GROUP");
        !           129:         get_job_property (j_namespace, 511, pids[i], "NAMESPACE");
        !           130:         get_job_property (j_io, 511, pids[i], "$IO");
        !           131:         get_job_property (j_tlevel, 511, pids[i], "$TLEVEL");
        !           132:         get_job_property (j_routine, 511, pids[i], "ROUTINE");
        !           133:         
        !           134:         printf ("%-8ld %-8s %-8s %-12s %-30s %-10s %s\n", pids[i], j_uid, j_gid, j_namespace, j_io, j_tlevel, j_routine); 
        !           135: 
        !           136: 
        !           137:     }
        !           138: 
        !           139:     printf ("\n\n    - %d jobs examined\n\n", pidct);
        !           140:     
        !           141:     return 0;
        !           142: 
        !           143: }
        !           144: 
        !           145: void get_job_property (char *tbuf, int length, long jobpid, char *property)
        !           146: {
        !           147:     char tkey[512];
        !           148:     int i;
        !           149: 
        !           150:     snprintf (tkey, 512 - 1, "^$JOB\202%ld\202%s\201\201\201", jobpid, property);
        !           151:     //stcnv_c2m (key);
        !           152: 
        !           153:     ssvn (get_sym, tkey, tbuf);
        !           154:     
        !           155:     for (i = 0; i < length; i++) {
        !           156:         if (tbuf[i] == '\201') tbuf[i] = '\0';
        !           157:     }
        !           158: 
        !           159: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>