Annotation of src/distrib/utils/sysinst/checkrc.c, Revision 1.1
1.1 ! riz 1: /* $NetBSD$ */
! 2:
! 3: /*-
! 4: * Copyright (c) 2012 The NetBSD Foundation, Inc.
! 5: * All rights reserved.
! 6: *
! 7: * This code is derived from software contributed to The NetBSD Foundation
! 8: * by Jeffrey C. Rizzo
! 9: *
! 10: * Redistribution and use in source and binary forms, with or without
! 11: * modification, are permitted provided that the following conditions
! 12: * are met:
! 13: * 1. Redistributions of source code must retain the above copyright
! 14: * notice, this list of conditions and the following disclaimer.
! 15: * 2. Redistributions in binary form must reproduce the above copyright
! 16: * notice, this list of conditions and the following disclaimer in the
! 17: * documentation and/or other materials provided with the distribution.
! 18: *
! 19: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
! 20: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 21: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 22: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
! 23: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! 24: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! 25: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! 26: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 27: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! 28: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 29: * POSSIBILITY OF SUCH DAMAGE.
! 30: */
! 31:
! 32: /* checkrc.c -- Create a script on the target to check the state of
! 33: * its rc.conf variables. */
! 34:
! 35: #include <curses.h>
! 36: #include <err.h>
! 37: #include <stdio.h>
! 38: #include "defs.h"
! 39: #include "msg_defs.h"
! 40: #include "menu_defs.h"
! 41:
! 42: #define RC_CHECK_SCRIPT "/tmp/checkrc.sh"
! 43:
! 44: static int create_script(const char *, int);
! 45: static int check(const char *, int);
! 46:
! 47: char *rcconf = NULL;
! 48:
! 49: enum {
! 50: CHECK_CONF,
! 51: CHECK_DEFAULT
! 52: };
! 53:
! 54: static int
! 55: create_script(const char *varname, int filetocheck)
! 56: {
! 57: FILE *fp;
! 58:
! 59: if ((fp = fopen(target_expand(RC_CHECK_SCRIPT), "w")) == NULL) {
! 60: if (logfp)
! 61: fprintf(logfp,"Could not open %s for writing",
! 62: target_expand(RC_CHECK_SCRIPT));
! 63: warn("Could not open %s for writing",
! 64: target_expand(RC_CHECK_SCRIPT));
! 65: return 1;
! 66: }
! 67:
! 68: if (filetocheck == CHECK_DEFAULT)
! 69: fprintf(fp, "#!/bin/sh\n. /etc/defaults/rc.conf\n"
! 70: ". /etc/rc.subr\n");
! 71: else
! 72: fprintf(fp, "#!/bin/sh\n. /etc/rc.conf\n. /etc/rc.subr\n");
! 73: fprintf(fp, "if checkyesno %s\nthen\necho YES\nelse\necho NO\nfi\n",
! 74: varname);
! 75:
! 76: fclose(fp);
! 77: return 0;
! 78: }
! 79:
! 80: static int
! 81: check(const char *varname, int filetocheck)
! 82: {
! 83: char *buf;
! 84:
! 85: create_script(varname, filetocheck);
! 86:
! 87: collect(T_OUTPUT, &buf, "chroot %s /bin/sh %s 2>&1", target_prefix(),
! 88: RC_CHECK_SCRIPT);
! 89:
! 90: unlink(target_expand(RC_CHECK_SCRIPT));
! 91:
! 92: if (logfp) {
! 93: fprintf(logfp,"var %s is %s\n", varname, buf);
! 94: fflush(logfp);
! 95: }
! 96:
! 97: if (strncmp(buf, "YES", strlen("YES")) == 0)
! 98: return 1;
! 99: else
! 100: return 0;
! 101: }
! 102:
! 103: int
! 104: check_rcvar(const char *varname)
! 105: {
! 106: return check(varname, CHECK_CONF);
! 107: }
! 108:
! 109: int
! 110: check_rcdefault(const char *varname)
! 111: {
! 112: return check(varname, CHECK_DEFAULT);
! 113: }
CVSweb <webmaster@jp.NetBSD.org>