xref: /aosp_15_r20/external/mtools/precmd.c (revision d5c9a868b113e0ec0db2f27bc2ce8a253e77c4b0)
1*d5c9a868SElliott Hughes /*  Copyright 1997,1999,2001-2004,2007,2009 Alain Knaff.
2*d5c9a868SElliott Hughes  *  This file is part of mtools.
3*d5c9a868SElliott Hughes  *
4*d5c9a868SElliott Hughes  *  Mtools is free software: you can redistribute it and/or modify
5*d5c9a868SElliott Hughes  *  it under the terms of the GNU General Public License as published by
6*d5c9a868SElliott Hughes  *  the Free Software Foundation, either version 3 of the License, or
7*d5c9a868SElliott Hughes  *  (at your option) any later version.
8*d5c9a868SElliott Hughes  *
9*d5c9a868SElliott Hughes  *  Mtools is distributed in the hope that it will be useful,
10*d5c9a868SElliott Hughes  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11*d5c9a868SElliott Hughes  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*d5c9a868SElliott Hughes  *  GNU General Public License for more details.
13*d5c9a868SElliott Hughes  *
14*d5c9a868SElliott Hughes  *  You should have received a copy of the GNU General Public License
15*d5c9a868SElliott Hughes  *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
16*d5c9a868SElliott Hughes  *
17*d5c9a868SElliott Hughes  * Do filename expansion with the shell.
18*d5c9a868SElliott Hughes  */
19*d5c9a868SElliott Hughes 
20*d5c9a868SElliott Hughes #include "sysincludes.h"
21*d5c9a868SElliott Hughes #include "mtools.h"
22*d5c9a868SElliott Hughes 
precmd(struct device * dev)23*d5c9a868SElliott Hughes void precmd(struct device *dev)
24*d5c9a868SElliott Hughes {
25*d5c9a868SElliott Hughes #ifndef OS_mingw32msvc
26*d5c9a868SElliott Hughes 	int status;
27*d5c9a868SElliott Hughes 	pid_t pid;
28*d5c9a868SElliott Hughes 
29*d5c9a868SElliott Hughes 	if(!dev || !dev->precmd)
30*d5c9a868SElliott Hughes 		return;
31*d5c9a868SElliott Hughes 
32*d5c9a868SElliott Hughes 	switch((pid=fork())){
33*d5c9a868SElliott Hughes 		case -1:
34*d5c9a868SElliott Hughes 			perror("Could not fork");
35*d5c9a868SElliott Hughes 			exit(1);
36*d5c9a868SElliott Hughes 		case 0: /* the son */
37*d5c9a868SElliott Hughes 			execl("/bin/sh", "sh", "-c", dev->precmd, (char *)NULL);
38*d5c9a868SElliott Hughes 			break;
39*d5c9a868SElliott Hughes 		default:
40*d5c9a868SElliott Hughes 			wait(&status);
41*d5c9a868SElliott Hughes 			break;
42*d5c9a868SElliott Hughes 	}
43*d5c9a868SElliott Hughes #endif
44*d5c9a868SElliott Hughes }
45*d5c9a868SElliott Hughes 
46