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

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

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