![]() ![]() | ![]() |
1.1 snw 1: /*
2: * *
3: * * *
4: * * *
5: * ***************
6: * * * * *
7: * * MUMPS *
8: * * * * *
9: * ***************
10: * * *
11: * * *
12: * *
13: *
14: * fma_locks.c
15: * fmadm - locks
16: *
17: *
1.3 ! snw 18: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 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 <stdlib.h>
41: #include "config.h"
42:
43: #if defined(HAVE_GETOPT_H)
44: # include <getopt.h>
45: #endif
46:
47: #include "fmadm.h"
48:
49: #include <stdio.h>
50: #include <sys/types.h>
51: #include <unistd.h>
52: #include <ctype.h>
53: #include <sys/stat.h>
54: #include <fcntl.h>
55: #include "locktab.h"
56:
57: int unlock (char *locktab, long pid);
58: long int tell (int fd);
59:
60: int fma_locks_list (int optc, char **opts)
61: {
62:
63: printf ("\nFreeM Lock Table\n");
64: printf ("----------------\n\n");
65:
66: locktab_dump ();
67:
68: return 0;
69: } /* fma_locks_list() */
70:
71: int fma_locks_remove (int optc, char **opts)
72: {
73:
74: int ct;
75: int c;
76: int option_index = 0;
77: pid_t t_pid = 0;
78:
79: #if defined(HAVE_GETOPT_LONG)
80:
81: struct option long_options[] = {
82: {"pid", required_argument, 0, 'p'},
83: {0, 0, 0, 0}
84: };
85:
86: #endif
87:
88: #if defined(HAVE_GETOPT_LONG)
89:
90: while(1) {
91:
92: c = getopt_long (optc, opts, "p:", long_options, &option_index);
93:
94: if (c == -1) break;
95:
96: switch (c) {
97:
98: case 'p':
99: t_pid = atol (optarg);
100: break;
101:
102: }
103: }
104:
105:
106:
107:
108: #else
109:
110: #endif
111:
112: if (t_pid == 0) {
113: fprintf (stderr, "fmadm: must supply -p or --pid argument\n");
114: return 1;
115: }
116:
1.2 snw 117: printf ("\nRemoving all LOCKs for PID %ld:\t", (long) t_pid);
1.1 snw 118:
119: ct = unlock (fma_locktab, t_pid);
120:
121: if (ct >= 0) {
122: printf ("[%d MATCHES]\n\n", ct);
123: }
124: else {
125: printf ("[ERROR]\n\n");
126: }
127:
128: return ct >= 0 ? 0 : 1;
129:
130: } /* fma_locks_remove() */
131:
132: /* unLOCK all entries of pid */
133: int unlock (char *locktab, long n_pid)
134: {
135: pid_t old_pid = pid;
136: pid = n_pid;
137:
138:
139: if (locktab_get_sem () == TRUE) {
140:
141: locktab_unlock_all ();
142:
143: pid = old_pid;
144: locktab_release_sem ();
145:
146: return 1;
147: }
148: else {
149: fprintf (stderr, "fmadm: could not acquire LOCK table semaphore\n");
150: pid = old_pid;
151: return 0;
152: }
153:
154: pid = old_pid;
155: return 0;
156:
157: } /* lock() */