File:  [Coherent Logic Development] / freem / src / fma_jobs.c
Revision 1.5: download - view: text, annotated - select for diffs
Sun Apr 13 04:22:43 2025 UTC (3 months, 2 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Fix snprintf calls

    1: /*
    2:  *   $Id: fma_jobs.c,v 1.5 2025/04/13 04:22:43 snw Exp $
    3:  *    fmadm - jobs
    4:  *
    5:  *  
    6:  *   Author: Serena Willis <snw@coherent-logic.com>
    7:  *    Copyright (C) 1998 MUG Deutschland
    8:  *    Copyright (C) 2020, 2025 Coherent Logic Development LLC
    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:  *
   26:  *   $Log: fma_jobs.c,v $
   27:  *   Revision 1.5  2025/04/13 04:22:43  snw
   28:  *   Fix snprintf calls
   29:  *
   30:  *   Revision 1.4  2025/04/10 01:24:38  snw
   31:  *   Remove C++ style comments
   32:  *
   33:  *   Revision 1.3  2025/03/09 19:14:25  snw
   34:  *   First phase of REUSE compliance and header reformat
   35:  *
   36:  *
   37:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
   38:  * SPDX-License-Identifier: AGPL-3.0-or-later
   39:  **/
   40: 
   41: #include <stdio.h>
   42: #include <stdlib.h>
   43: #include <string.h>
   44: #include <dirent.h>
   45: #include <stdlib.h>
   46: #include <time.h>
   47: #include <unistd.h>
   48: #include <sys/types.h>
   49: #include <sys/stat.h>
   50: #include <ctype.h>
   51: 
   52: #include "fmadm.h"
   53: #include "freem.h"
   54: #include "jobtab.h"
   55: 
   56: void get_job_property (char *tbuf, int length, long jobpid, char *property);
   57: 
   58: int fma_jobs_list (int optc, char **opts)
   59: {
   60:     printf ("\nFreeM Job Listing\n");
   61:     printf (  "-----------------\n\n");
   62: 
   63:     job_dump ();
   64:     
   65:     return 0;
   66: }
   67: 
   68: int fma_jobs_remove (int optc, char **opts)
   69: {
   70:     int i;
   71:     pid_t job_pid;
   72:     
   73:     for (i = fma_base_opt; i < optc; i++) {
   74: 
   75:         job_pid = atol (opts[i]);
   76: 
   77:         kill (job_pid, SIGTERM);
   78:         
   79:     }
   80: 
   81:     return 0;
   82: }
   83: 
   84: int fma_jobs_examine (int optc, char **opts)
   85: {
   86:     long pids[FMA_MAXPID];
   87: 
   88:     register int i;
   89:     register int j = 0;
   90:     register int pidct = optc - 1;
   91: 
   92: 
   93:     char j_uid[512];
   94:     char j_gid[512];
   95:     char j_namespace[512];
   96:     char j_io[512];
   97:     char j_tlevel[512];
   98:     char j_routine[512];
   99: 
  100: 
  101:     if (pidct < 1) {
  102:         fprintf (stderr, "usage:  fmadm examine job <namespace> pid1 pid2 ...pidN\n");
  103:         return 1;
  104:     }
  105: 
  106:     for (i = fma_base_opt; i < optc; i++) {
  107:         if (i == FMA_MAXPID) break;
  108:         pids[j++] = atol (opts[i]);
  109:     }
  110: 
  111:     printf ("\nFreeM Job Examine\n");
  112:     printf ("-----------------\n\n");
  113: 
  114:     printf ("PIDs:    ");
  115: 
  116:     for (i = 0; i < pidct; i++) {
  117:         printf ("%ld ", pids[i]);
  118:     }
  119: 
  120:     printf ("\n\n");
  121: 
  122:     /* pid uid gid namespace io tlevel routine */
  123:     printf ("%-8s %-8s %-8s %-12s %-30s %-10s %s\n", "PID", "UID", "GID", "NAMESPACE", "$IO", "$TLEVEL", "ROUTINE");
  124:     printf ("%-8s %-8s %-8s %-12s %-30s %-10s %s\n", "---", "---", "---", "---------", "---", "-------", "-------");
  125: 
  126:     for (i = 0; i < pidct; i++) {
  127: 
  128:         get_job_property (j_uid, 511, pids[i], "USER");
  129:         get_job_property (j_gid, 511, pids[i], "GROUP");
  130:         get_job_property (j_namespace, 511, pids[i], "NAMESPACE");
  131:         get_job_property (j_io, 511, pids[i], "$IO");
  132:         get_job_property (j_tlevel, 511, pids[i], "$TLEVEL");
  133:         get_job_property (j_routine, 511, pids[i], "ROUTINE");
  134:         
  135:         printf ("%-8ld %-8s %-8s %-12s %-30s %-10s %s\n", pids[i], j_uid, j_gid, j_namespace, j_io, j_tlevel, j_routine); 
  136: 
  137: 
  138:     }
  139: 
  140:     printf ("\n\n    - %d jobs examined\n\n", pidct);
  141:     
  142:     return 0;
  143: 
  144: }
  145: 
  146: void get_job_property (char *tbuf, int length, long jobpid, char *property)
  147: {
  148:     char tkey[512];
  149:     int i;
  150: 
  151:     snprintf (tkey, sizeof (tkey) - 1, "^$JOB\202%ld\202%s\201\201\201", jobpid, property);
  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>