]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/support/bboards/bbexp.c
1 /* bbexp.c - expunge the BBoards area */
3 static char ident
[] = "@(#)$Id: bbexp.c,v 1.6 1992/12/15 00:20:22 jromine Exp $";
7 #include "../h/dropsbr.h"
8 #include "../zotnet/bboards.h"
12 #include <sys/types.h>
20 static int broken_pipe
;
23 static process(), chgrp();
29 struct passwd
*getpwnam ();
47 invo_name
= r1bindex (*argv
++, '/');
50 if ((pw
= getpwnam (BBOARDS
)) == NULL
)
51 adios (NULLCP
, "no entry for ~%s", BBOARDS
);
52 if (pw
-> pw_uid
!= geteuid ())
53 adios (NULLCP
, "not running setuid to %s", BBOARDS
);
55 if (*argv
&& **argv
== '-') {
56 if ((first
= atoi (*argv
+ 1)) < 1)
60 if (*argv
&& **argv
== '-') {
61 if ((second
= atoi (*argv
+ 1)) < 1)
66 (void) setbbent (SB_STAY
);
68 while (bb
= getbbent ()) {
69 if ((bb
-> bb_flags
& BB_ARCH
) & (BB_ASAV
| BB_AREM
))
70 process (bb
, pw
, first
, second
);
74 if ((bb
= getbbnam (cp
)) || (bb
= getbbaka (cp
))) {
75 if ((bb
-> bb_flags
& BB_ARCH
) & (BB_ASAV
| BB_AREM
))
76 process (bb
, pw
, first
, second
);
79 advise (NULLCP
, "no such BBoard as %s", cp
);
87 static process (bb
, pw
, first
, second
)
101 if ((fd
= lkopen (bb
-> bb_file
, 6)) == NOTOK
) {
102 advise (bb
-> bb_file
, "unable to lock and open");
106 (void) sprintf (tmpfil
, "%s/#bbexpXXXXXX", pw
-> pw_dir
);
107 (void) unlink (mktemp (tmpfil
));
108 if ((td
= creat (tmpfil
, BBMODE
)) == NOTOK
) {
109 advise (tmpfil
, "unable to create");
113 if ((td
= creat (cp
= map_name (tmpfil
), BBMODE
)) == NOTOK
) {
114 advise (cp
, "unable to create");
119 if ((bb
-> bb_flags
& BB_ARCH
)
120 && stat (bb
-> bb_archive
, &st
) == NOTOK
121 && stat (bb
-> bb_file
, &st
) != NOTOK
122 && (td
= creat (bb
-> bb_archive
, (int) (st
.st_mode
& 0777))) != NOTOK
)
125 (void) sprintf (command
, "%s %s%s", mshproc
, bb
-> bb_file
,
126 isatty (fileno (stdout
)) ? " 2>&1 | cat" : "");
127 printf ("%s (%s old messages)\n", command
,
128 (bb
-> bb_flags
& BB_ARCH
) == BB_ASAV
? "archive" : "remove");
129 (void) fflush (stdout
);
130 if ((pf
= popen (command
, "w")) == NULL
) {
131 advise (NULLCP
, "unable to popen \"%s\" for writing", command
);
134 (void) signal (SIGPIPE
, pipeser
);
137 fprintf (pf
, "pick %s -before -%d -sequence select -zero\n",
138 "-datefield BB-Posted", first
);
139 fprintf (pf
, "pick -before -%d -sequence select -nozero\n", second
);
140 fprintf (pf
, "scan select\n");
141 if ((bb
-> bb_flags
& BB_ARCH
) == BB_ASAV
)
142 fprintf (pf
, "pack select -file %s\n", bb
-> bb_archive
);
143 fprintf (pf
, "rmm select\n");
144 fprintf (pf
, "packf all -file %s\n", tmpfil
);
145 #ifdef notdef /* want real EOF to end it */
146 fprintf (pf
, "quit\n");
148 if (td
= pclose (pf
))
149 advise (NULLCP
, "msh returns %d", td
);
150 (void) signal (SIGPIPE
, SIG_DFL
);
152 if (move (tmpfil
, bb
-> bb_file
) != NOTOK
)
153 (void) move (cp
, bb
-> bb_map
);
158 (void) unlink (tmpfil
);
160 (void) lkclose (fd
, bb
-> bb_file
);
165 static int move (input
, output
)
175 if ((in
= open (input
, 0)) == NOTOK
) {
176 advise (input
, "unable to re-open");
180 i
= stat (output
, &st1
);
181 if ((out
= creat (output
, BBMODE
)) == NOTOK
) {
182 advise (output
, "unable to re-create");
185 if (i
!= NOTOK
&& chmod (output
, (int) (st1
.st_mode
& 0777)) == NOTOK
)
186 admonish (output
, "unable to change mode of");
187 if (i
!= NOTOK
&& stat (output
, &st2
) != NOTOK
&& st2
.st_gid
!= st1
.st_gid
)
188 chgrp (output
, st1
.st_gid
);
190 cpydata (in
, out
, input
, output
);
200 static chgrp (file
, gid
)
207 switch (child_id
= fork ()) {
209 admonish ("fork", "unable to");
213 (void) setuid (geteuid ());
214 (void) sprintf (group
, "%d", gid
);
215 execlp ("/bin/chgrp", chgrp
, group
, file
, NULLCP
);
216 fprintf (stderr
, "unable to exec ");
217 perror ("/bin/chgrp");
221 (void) pidwait (child_id
, OK
);
230 static int pipeser (i
)
234 (void) signal (SIGPIPE
, pipeser
);
235 #endif /* not BSD42 */
238 advise (NULLCP
, "broken pipe");