4 * Copyright (c) 1997-2009 Erez Zadok
5 * Copyright (c) 1989 Jan-Simon Pendry
6 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1989 The Regents of the University of California.
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgment:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * File: am-utils/amd/amfs_program.c
52 #endif /* HAVE_CONFIG_H */
56 /* forward definitions */
57 static char *amfs_program_match(am_opts
*fo
);
58 static int amfs_program_mount(am_node
*am
, mntfs
*mf
);
59 static int amfs_program_umount(am_node
*am
, mntfs
*mf
);
60 static int amfs_program_init(mntfs
*mf
);
65 am_ops amfs_program_ops
=
72 amfs_error_lookup_child
,
73 amfs_error_mount_child
,
75 0, /* amfs_program_readlink */
76 0, /* amfs_program_mounted */
77 0, /* amfs_program_umounted */
78 amfs_generic_find_srvr
,
79 0, /* amfs_program_get_wchan */
80 FS_MKMNT
| FS_BACKGROUND
| FS_AMQINFO
, /* nfs_fs_flags */
82 AUTOFS_PROGRAM_FS_FLAGS
,
83 #endif /* HAVE_FS_AUTOFS */
88 * Execute needs a mount and unmount command.
91 amfs_program_match(am_opts
*fo
)
95 if (fo
->opt_unmount
&& fo
->opt_umount
) {
96 plog(XLOG_ERROR
, "program: cannot specify both unmount and umount options");
100 plog(XLOG_ERROR
, "program: must specify mount command");
103 if (!fo
->opt_unmount
&& !fo
->opt_umount
) {
104 fo
->opt_unmount
= str3cat(NULL
, UNMOUNT_PROGRAM
, " umount ", fo
->opt_fs
);
105 plog(XLOG_INFO
, "program: un/umount not specified; using default \"%s\"",
108 prog
= strchr(fo
->opt_mount
, ' ');
110 return strdup(prog
? prog
+ 1 : fo
->opt_mount
);
115 amfs_program_init(mntfs
*mf
)
117 /* check if already saved value */
118 if (mf
->mf_private
!= NULL
)
121 /* save unmount (or umount) command */
122 if (mf
->mf_fo
->opt_unmount
!= NULL
)
123 mf
->mf_private
= (opaque_t
) strdup(mf
->mf_fo
->opt_unmount
);
125 mf
->mf_private
= (opaque_t
) strdup(mf
->mf_fo
->opt_umount
);
126 mf
->mf_prfree
= (void (*)(opaque_t
)) free
;
133 amfs_program_exec(char *info
)
139 * Split copy of command info string
144 xivec
= strsplit(info
, ' ', '\'');
147 * Put stdout to stderr
149 (void) fclose(stdout
);
151 logfp
= stderr
; /* initialize before possible first use */
152 (void) dup(fileno(logfp
));
153 if (fileno(logfp
) != fileno(stderr
)) {
154 (void) fclose(stderr
);
155 (void) dup(fileno(logfp
));
161 if (amuDebug(D_FULL
)) {
163 plog(XLOG_DEBUG
, "executing (un)mount command...");
165 plog(XLOG_DEBUG
, "arg[%ld] = '%s'", (long) (cp
- xivec
), *cp
);
170 if (xivec
[0] == 0 || xivec
[1] == 0) {
172 plog(XLOG_USER
, "1st/2nd args missing to (un)mount program");
174 (void) execv(xivec
[0], xivec
+ 1);
181 plog(XLOG_ERROR
, "exec failed: %m");
184 * Free allocate memory
197 amfs_program_mount(am_node
*am
, mntfs
*mf
)
199 return amfs_program_exec(mf
->mf_fo
->opt_mount
);
204 amfs_program_umount(am_node
*am
, mntfs
*mf
)
206 return amfs_program_exec((char *) mf
->mf_private
);