dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / srptsvc / srptsvc.c
blobd5442cbd680d1338d163a494c99911439b708807
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <stdio.h>
27 #include <libintl.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <locale.h>
32 #include <errno.h>
33 #include <unistd.h>
34 #include <strings.h>
35 #include <libscf.h> /* for SMF error exit codes */
37 #include <srpt_ioctl.h>
40 /* Globals */
41 char cmdName[] = "svc-srpt";
43 int
44 main(int argc, char *argv[])
46 int ret;
47 boolean_t do_enable = B_FALSE;
48 int srpt_ioctl;
49 int fd = -1;
50 int saverr;
51 char *txt;
52 struct stat statbuf;
54 (void) setlocale(LC_ALL, "");
56 if (argc < 2 || argc > 2) {
57 goto usage;
60 if (strcasecmp(argv[1], "start") == 0) {
61 do_enable = B_TRUE;
62 srpt_ioctl = SRPT_IOC_ENABLE_SVC;
63 } else if (strcasecmp(argv[1], "stop") == 0) {
64 srpt_ioctl = SRPT_IOC_DISABLE_SVC;
65 } else {
66 goto usage;
69 fd = open(SRPT_NODE, O_RDONLY);
70 if (fd < 0) {
71 saverr = errno;
73 (void) fprintf(stderr, "%s: %s (%s): %s\n", cmdName,
74 gettext("Could not open SRP Target pseudodevice"),
75 SRPT_NODE, strerror(saverr));
77 if (saverr == ENOENT) {
78 /* avoid having the service go into maintenance */
79 if ((stat("/devices/ib", &statbuf)) != 0) {
80 (void) fprintf(stderr, "%s: %s\n", cmdName,
81 gettext(
82 "No InfiniBand devices on this system."));
84 ret = 0;
86 } else {
87 ret = SMF_EXIT_ERR_FATAL; /* avoid retries */
90 (void) fprintf(stderr, "%s: %s\n", cmdName,
91 gettext("SRPT Driver may not be loaded."));
93 return (ret);
96 ret = ioctl(fd, srpt_ioctl, NULL);
97 if (ret != 0) {
98 if (do_enable) {
99 txt = gettext("Could not enable SRP Target");
100 } else {
101 txt = gettext("Could not disable SRP Target");
104 (void) fprintf(stderr, "%s: %d", txt, ret);
105 ret = SMF_EXIT_ERR_FATAL;
108 (void) close(fd);
110 return (ret);
112 usage:
113 (void) fprintf(stderr, gettext("Usage: %s start|stop"), cmdName);
114 (void) fprintf(stderr, "\n");
116 return (1);