File:  [Coherent Logic Development] / freem / src / fma_jobs.c
Revision 1.3: download - view: text, annotated - select for diffs
Sun Mar 9 19:14:25 2025 UTC (4 months, 3 weeks ago) by snw
Branches: MAIN
CVS tags: v0-63-1-rc1, v0-63-0-rc1, v0-63-0, v0-62-3, v0-62-2, v0-62-1, v0-62-0, HEAD
First phase of REUSE compliance and header reformat

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

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