003 File Manager
Current Path:
/usr/src/contrib/sendmail/libsm
usr
/
src
/
contrib
/
sendmail
/
libsm
/
📁
..
📄
Makefile
(346 B)
📄
Makefile.m4
(1.92 KB)
📄
README
(4.42 KB)
📄
assert.c
(4.13 KB)
📄
assert.html
(13.86 KB)
📄
b-strcmp.c
(3.4 KB)
📄
b-strl.c
(5 KB)
📄
cdefs.html
(2.39 KB)
📄
cf.c
(1.97 KB)
📄
clock.c
(13.89 KB)
📄
clrerr.c
(872 B)
📄
config.c
(4.47 KB)
📄
debug.c
(8.91 KB)
📄
debug.html
(7.68 KB)
📄
errstring.c
(6.03 KB)
📄
exc.c
(13.05 KB)
📄
exc.html
(23.27 KB)
📄
fclose.c
(3.13 KB)
📄
feof.c
(961 B)
📄
ferror.c
(932 B)
📄
fflush.c
(3.1 KB)
📄
fget.c
(2.37 KB)
📄
findfp.c
(10.65 KB)
📄
flags.c
(1.27 KB)
📄
fopen.c
(8.3 KB)
📄
fpos.c
(3.12 KB)
📄
fprintf.c
(1.35 KB)
📄
fpurge.c
(1.15 KB)
📄
fput.c
(1.25 KB)
📄
fread.c
(2.28 KB)
📄
fscanf.c
(1.34 KB)
📄
fseek.c
(7.25 KB)
📄
fvwrite.c
(6.24 KB)
📄
fvwrite.h
(740 B)
📄
fwalk.c
(1.41 KB)
📄
fwrite.c
(1.54 KB)
📄
gen.html
(910 B)
📄
get.c
(1.12 KB)
📄
glue.h
(731 B)
📄
heap.c
(17.29 KB)
📄
heap.html
(13.07 KB)
📄
index.html
(5.95 KB)
📄
inet6_ntop.c
(1.1 KB)
📄
io.html
(26.6 KB)
📄
ldap.c
(35.72 KB)
📄
local.h
(9.42 KB)
📄
makebuf.c
(3.36 KB)
📄
match.c
(2.77 KB)
📄
mbdb.c
(16.61 KB)
📄
memstat.c
(5.13 KB)
📄
mpeix.c
(13.84 KB)
📄
niprop.c
(4.64 KB)
📄
notify.c
(3.32 KB)
📄
put.c
(1.61 KB)
📄
refill.c
(7.09 KB)
📄
rewind.c
(1.08 KB)
📄
rpool.c
(11.54 KB)
📄
rpool.html
(6.08 KB)
📄
sem.c
(4.41 KB)
📄
setvbuf.c
(4.2 KB)
📄
shm.c
(2.62 KB)
📄
signal.c
(6.75 KB)
📄
smstdio.c
(6.14 KB)
📄
snprintf.c
(2.29 KB)
📄
sscanf.c
(2.26 KB)
📄
stdio.c
(9.7 KB)
📄
strcasecmp.c
(3.14 KB)
📄
strdup.c
(2.79 KB)
📄
strerror.c
(1.27 KB)
📄
strexit.c
(2.76 KB)
📄
string.c
(1.29 KB)
📄
stringf.c
(1.77 KB)
📄
strio.c
(9.18 KB)
📄
strl.c
(7.52 KB)
📄
strrevcmp.c
(1.61 KB)
📄
strto.c
(5.45 KB)
📄
syslogio.c
(4.11 KB)
📄
t-cf.c
(934 B)
📄
t-event.c
(1.79 KB)
📄
t-exc.c
(2.75 KB)
📄
t-fget.c
(1.71 KB)
📄
t-float.c
(1.78 KB)
📄
t-fopen.c
(875 B)
📄
t-heap.c
(1.3 KB)
📄
t-inet6_ntop.c
(1.4 KB)
📄
t-match.c
(1.1 KB)
📄
t-memstat.c
(2.17 KB)
📄
t-notify.c
(1.81 KB)
📄
t-path.c
(742 B)
📄
t-qic.c
(5.43 KB)
📄
t-rpool.c
(1.5 KB)
📄
t-scanf.c
(1.38 KB)
📄
t-sem.c
(5.85 KB)
📄
t-shm.c
(4.42 KB)
📄
t-smstdio.c
(1.55 KB)
📄
t-string.c
(968 B)
📄
t-strio.c
(775 B)
📄
t-strl.c
(3.53 KB)
📄
t-strrevcmp.c
(994 B)
📄
t-types.c
(2.7 KB)
📄
test.c
(2.73 KB)
📄
ungetc.c
(3.93 KB)
📄
util.c
(4.46 KB)
📄
vasprintf.c
(2.91 KB)
📄
vfprintf.c
(24.09 KB)
📄
vfscanf.c
(18.76 KB)
📄
vprintf.c
(999 B)
📄
vsnprintf.c
(1.87 KB)
📄
wbuf.c
(2.51 KB)
📄
wsetup.c
(1.88 KB)
📄
xtrap.c
(653 B)
Editing: t-sem.c
/* * Copyright (c) 2000-2001, 2005-2008 Proofpoint, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set * forth in the LICENSE file which can be found at the top level of * the sendmail distribution. */ #include <sm/gen.h> SM_RCSID("@(#)$Id: t-sem.c,v 1.18 2013-11-22 20:51:43 ca Exp $") #include <stdio.h> #if SM_CONF_SEM # include <stdlib.h> # include <unistd.h> # include <sysexits.h> # include <sm/heap.h> # include <sm/string.h> # include <sm/signal.h> # include <sm/test.h> # include <sm/sem.h> # define T_SM_SEM_KEY (4321L) static void delay(t, s) int t; char *s; { if (t > 0) { #if DEBUG fprintf(stderr, "sleep(%d) before %s\n", t, s); #endif sleep(t); } #if DEBUG fprintf(stderr, "%s\n", s); #endif } /* ** SEMINTER -- interactive testing of semaphores. ** ** Parameters: ** owner -- create semaphores. ** ** Returns: ** 0 on success ** < 0 on failure. */ static int seminter(owner) bool owner; { int semid; int t; semid = sm_sem_start(T_SM_SEM_KEY, SM_NSEM, 0, owner); if (semid < 0) { perror("sm_sem_start failed"); return 1; } while ((t = getchar()) != EOF) { switch (t) { case 'a': delay(0, "try to acq"); if (sm_sem_acq(semid, 0, 2) < 0) { perror("sm_sem_acq failed"); return 1; } delay(0, "acquired"); break; case 'r': delay(0, "try to rel"); if (sm_sem_rel(semid, 0, 2) < 0) { perror("sm_sem_rel failed"); return 1; } delay(0, "released"); break; case 'v': if ((t = sm_sem_get(semid, 0)) < 0) { perror("get_sem failed"); return 1; } printf("semval: %d\n", t); break; } } if (owner) return sm_sem_stop(semid); return 0; } /* ** SEM_CLEANUP -- cleanup if something breaks ** ** Parameters: ** sig -- signal. ** ** Returns: ** none. */ static int semid_c = -1; void sem_cleanup(sig) int sig; { if (semid_c >= 0) (void) sm_sem_stop(semid_c); exit(EX_UNAVAILABLE); } static int drop_priv(uid, gid) uid_t uid; gid_t gid; { int r; r = setgid(gid); if (r != 0) return r; r = setuid(uid); return r; } /* ** SEMTEST -- test of semaphores ** ** Parameters: ** owner -- create semaphores. ** ** Returns: ** 0 on success ** < 0 on failure. */ # define MAX_CNT 10 static int semtest(owner, uid, gid) int owner; uid_t uid; gid_t gid; { int semid, r; int cnt = 0; if (!owner && uid != 0) { r = drop_priv(uid, gid); if (r < 0) { perror("drop_priv child failed"); return -1; } } semid = sm_sem_start(T_SM_SEM_KEY, 1, 0, owner); if (semid < 0) { perror("sm_sem_start failed"); return -1; } if (owner) { if (uid != 0) { r = sm_semsetowner(semid, uid, gid, 0660); if (r < 0) { perror("sm_semsetowner failed"); return -1; } r = drop_priv(uid, gid); if (r < 0) { perror("drop_priv owner failed"); return -1; } } /* just in case someone kills the program... */ semid_c = semid; (void) sm_signal(SIGHUP, sem_cleanup); (void) sm_signal(SIGINT, sem_cleanup); (void) sm_signal(SIGTERM, sem_cleanup); delay(1, "parent: acquire 1"); cnt = 0; do { r = sm_sem_acq(semid, 0, 0); if (r < 0) { sleep(1); ++cnt; } } while (r < 0 && cnt <= MAX_CNT); SM_TEST(r >= 0); if (r < 0) return r; delay(3, "parent: release 1"); cnt = 0; do { r = sm_sem_rel(semid, 0, 0); if (r < 0) { sleep(1); ++cnt; } } while (r < 0 && cnt <= MAX_CNT); SM_TEST(r >= 0); if (r < 0) return r; delay(1, "parent: getval"); cnt = 0; do { r = sm_sem_get(semid, 0); if (r <= 0) { sleep(1); ++cnt; } } while (r <= 0 && cnt <= MAX_CNT); SM_TEST(r > 0); if (r <= 0) return r; delay(1, "parent: acquire 2"); cnt = 0; do { r = sm_sem_acq(semid, 0, 0); if (r < 0) { sleep(1); ++cnt; } } while (r < 0 && cnt <= MAX_CNT); SM_TEST(r >= 0); if (r < 0) return r; cnt = 0; do { r = sm_sem_rel(semid, 0, 0); if (r < 0) { sleep(1); ++cnt; } } while (r < 0 && cnt <= MAX_CNT); SM_TEST(r >= 0); if (r < 0) return r; } else { delay(1, "child: acquire 1"); cnt = 0; do { r = sm_sem_acq(semid, 0, 0); if (r < 0) { sleep(1); ++cnt; } } while (r < 0 && cnt <= MAX_CNT); SM_TEST(r >= 0); if (r < 0) return r; delay(1, "child: release 1"); cnt = 0; do { r = sm_sem_rel(semid, 0, 0); if (r < 0) { sleep(1); ++cnt; } } while (r < 0 && cnt <= MAX_CNT); SM_TEST(r >= 0); if (r < 0) return r; } if (owner) return sm_sem_stop(semid); return 0; } int main(argc, argv) int argc; char *argv[]; { bool interactive = false; bool owner = false; int ch, r; uid_t uid; gid_t gid; uid = 0; gid = 0; r = 0; # define OPTIONS "iog:u:" while ((ch = getopt(argc, argv, OPTIONS)) != -1) { switch ((char) ch) { case 'g': gid = (gid_t)strtoul(optarg, 0, 0); break; case 'i': interactive = true; break; case 'u': uid = (uid_t)strtoul(optarg, 0, 0); break; case 'o': owner = true; break; default: break; } } if (interactive) r = seminter(owner); else { pid_t pid; printf("This test takes about 8 seconds.\n"); printf("If it takes longer than 30 seconds, please interrupt it\n"); printf("and compile again without semaphore support, i.e.,"); printf("-DSM_CONF_SEM=0\n"); if ((pid = fork()) < 0) { perror("fork failed\n"); return -1; } sm_test_begin(argc, argv, "test semaphores"); if (pid == 0) { /* give the parent the chance to setup data */ sleep(1); r = semtest(false, uid, gid); } else { r = semtest(true, uid, gid); } SM_TEST(r == 0); return sm_test_end(); } return r; } #else /* SM_CONF_SEM */ int main(argc, argv) int argc; char *argv[]; { printf("No support for semaphores configured on this machine\n"); return 0; } #endif /* SM_CONF_SEM */
Upload File
Create Folder