17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*113f4232Sakaplan * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* 347c478bd9Sstevel@tonic-gate * Implements the "putdgrp" command. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate #include <sys/types.h> 377c478bd9Sstevel@tonic-gate #include <stdio.h> 387c478bd9Sstevel@tonic-gate #include <stdlib.h> 397c478bd9Sstevel@tonic-gate #include <string.h> 407c478bd9Sstevel@tonic-gate #include <errno.h> 417c478bd9Sstevel@tonic-gate #include <unistd.h> 427c478bd9Sstevel@tonic-gate #include <fmtmsg.h> 437c478bd9Sstevel@tonic-gate #include <devmgmt.h> 447c478bd9Sstevel@tonic-gate #include <devtab.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * General Purpose Constants 497c478bd9Sstevel@tonic-gate * TRUE Boolean TRUE (if not already defined) 507c478bd9Sstevel@tonic-gate * FALSE Boolean FALSE (if not already defined) 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #ifndef TRUE 547c478bd9Sstevel@tonic-gate #define TRUE (1) 557c478bd9Sstevel@tonic-gate #endif 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate #ifndef FALSE 587c478bd9Sstevel@tonic-gate #define FALSE (0) 597c478bd9Sstevel@tonic-gate #endif 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * Exit codes 637c478bd9Sstevel@tonic-gate * EX_OK All went well 647c478bd9Sstevel@tonic-gate * EX_ERROR Usage or internal error 657c478bd9Sstevel@tonic-gate * EX_DGROUP Had trouble accessing/reading/writing the 667c478bd9Sstevel@tonic-gate * device-group table 677c478bd9Sstevel@tonic-gate * EX_NODGRP The specified device-group does not exist 687c478bd9Sstevel@tonic-gate * EX_NOMEM One or more device-group members requested for 697c478bd9Sstevel@tonic-gate * removal was not defined for the device 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate #define EX_OK 0 737c478bd9Sstevel@tonic-gate #define EX_ERROR 1 747c478bd9Sstevel@tonic-gate #define EX_DGROUP 2 757c478bd9Sstevel@tonic-gate #define EX_NODGRP 3 767c478bd9Sstevel@tonic-gate #define EX_NOMEM 4 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * Error messages 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #define E_USAGE "usage: putdgrp [-d] dgroup [device [...]]" 847c478bd9Sstevel@tonic-gate #define E_NODGRP "Device-group does not exist in table: %s" 857c478bd9Sstevel@tonic-gate #define E_NOTAMEM "Device-group member not found: %s" 867c478bd9Sstevel@tonic-gate #define E_NODGRPTAB "Cannot open the device-group table: %s" 877c478bd9Sstevel@tonic-gate #define E_NOMKTAB "Cannot create a new device-group table: %s" 887c478bd9Sstevel@tonic-gate #define E_INTERNAL "Internal error, errno=%d" 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * Macros 937c478bd9Sstevel@tonic-gate * stdmsg(r,l,s,t) Using fmtmsg(), write a standard message to the 947c478bd9Sstevel@tonic-gate * standard error stream. 957c478bd9Sstevel@tonic-gate * Where: 967c478bd9Sstevel@tonic-gate * r The recoverability of the error 977c478bd9Sstevel@tonic-gate * l The label-component 987c478bd9Sstevel@tonic-gate * s The severity-component 997c478bd9Sstevel@tonic-gate * t The text-component 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate #define stdmsg(r,l,s,t) (void) fmtmsg(MM_PRINT|MM_UTIL|r,l,s,t,MM_NULLACT,MM_NULLTAG) 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * Static data 1077c478bd9Sstevel@tonic-gate * msg Space for message's text-component 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate static char msg[256]; /* Space for text of message */ 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * char *mklbl(cmd) 1147c478bd9Sstevel@tonic-gate * char *cmd 1157c478bd9Sstevel@tonic-gate * 1167c478bd9Sstevel@tonic-gate * This function builds a standard label from the command used to invoke 1177c478bd9Sstevel@tonic-gate * this process and the standard label prefix ("UX:") 1187c478bd9Sstevel@tonic-gate * 1197c478bd9Sstevel@tonic-gate * Arguments: 1207c478bd9Sstevel@tonic-gate * char *cmd The command used to invoke this process. 1217c478bd9Sstevel@tonic-gate * 1227c478bd9Sstevel@tonic-gate * Returns: char * 1237c478bd9Sstevel@tonic-gate * Pointer to malloc()ed space containing the standard label, 1247c478bd9Sstevel@tonic-gate * or (char *) NULL if an error occurred. 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate static char * 1287c478bd9Sstevel@tonic-gate mklbl(cmd) 1297c478bd9Sstevel@tonic-gate char *cmd; 1307c478bd9Sstevel@tonic-gate { 1317c478bd9Sstevel@tonic-gate /* Automatic data */ 1327c478bd9Sstevel@tonic-gate char *rtn; /* Value to return */ 1337c478bd9Sstevel@tonic-gate char *p; /* Temporary */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* Find the 1st char of the basename of the command */ 1367c478bd9Sstevel@tonic-gate if (p = strrchr(cmd, '/')) p++; 1377c478bd9Sstevel@tonic-gate else p = cmd; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate /* Allocate and build the string value to return */ 1407c478bd9Sstevel@tonic-gate if (rtn = (char *) malloc(strlen("UX:")+strlen(p)+1)) { 1417c478bd9Sstevel@tonic-gate (void) strcpy(rtn, "UX:"); 1427c478bd9Sstevel@tonic-gate (void) strcat(rtn, p); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* Now that we've done all of this work, set up the environemnt 1467c478bd9Sstevel@tonic-gate * so that only the text-component is written (some requirements 1477c478bd9Sstevel@tonic-gate * say that standard messages are to be non-standard in SVR4.0, 1487c478bd9Sstevel@tonic-gate * this is supposed to change in SVR4.1) 1497c478bd9Sstevel@tonic-gate */ 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate (void) putenv("MSGVERB=text"); 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* Done */ 1547c478bd9Sstevel@tonic-gate return(rtn); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * putdgrp [-d] dgroup [device [...]] 1597c478bd9Sstevel@tonic-gate * 1607c478bd9Sstevel@tonic-gate * Options: 1617c478bd9Sstevel@tonic-gate * -d 1627c478bd9Sstevel@tonic-gate * 1637c478bd9Sstevel@tonic-gate * Arguments: 1647c478bd9Sstevel@tonic-gate * dgroup 1657c478bd9Sstevel@tonic-gate * device 1667c478bd9Sstevel@tonic-gate * 1677c478bd9Sstevel@tonic-gate * Exit values: 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate 170*113f4232Sakaplan int 171*113f4232Sakaplan main(int argc, char *argv[]) 1727c478bd9Sstevel@tonic-gate { 1737c478bd9Sstevel@tonic-gate /* Automatic data */ 1747c478bd9Sstevel@tonic-gate char **plist; /* Ptr to list of nonmembers */ 1757c478bd9Sstevel@tonic-gate char *lbl; /* Ptr to label for messages */ 1767c478bd9Sstevel@tonic-gate char *dgroup; /* Ptr to <dgroup> on command-line */ 1777c478bd9Sstevel@tonic-gate char *p; /* Temp ptr to char */ 1787c478bd9Sstevel@tonic-gate int noerr; /* FLAG, TRUE if all's well */ 1797c478bd9Sstevel@tonic-gate int d_seen; /* TRUE if -a seen on command-line */ 1807c478bd9Sstevel@tonic-gate int optchar; /* Option extracted */ 1817c478bd9Sstevel@tonic-gate int exitcd; /* Value to return at exit */ 1827c478bd9Sstevel@tonic-gate int nmems; /* Number of members on the cmd */ 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* Generate the label for messages */ 1867c478bd9Sstevel@tonic-gate lbl = mklbl(argv[0]); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* Extract arguments - validate usage */ 1897c478bd9Sstevel@tonic-gate noerr = TRUE; 1907c478bd9Sstevel@tonic-gate d_seen = FALSE; 1917c478bd9Sstevel@tonic-gate opterr = FALSE; 1927c478bd9Sstevel@tonic-gate while ((optchar = getopt(argc, argv, "d:")) != EOF) switch (optchar) { 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate case 'd': 1957c478bd9Sstevel@tonic-gate if (!d_seen) 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate d_seen = TRUE; 1987c478bd9Sstevel@tonic-gate dgroup = optarg; 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate else noerr = FALSE; 2017c478bd9Sstevel@tonic-gate break; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate case '?': 2047c478bd9Sstevel@tonic-gate default: 2057c478bd9Sstevel@tonic-gate noerr = FALSE; 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate /* Write a usage message if we've seen a blatant error */ 2107c478bd9Sstevel@tonic-gate if (!noerr || (!d_seen && ((nmems = argc - optind - 1) < 0)) || 2117c478bd9Sstevel@tonic-gate (d_seen && ((nmems = argc - optind) < 0))) { 2127c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_USAGE); 2137c478bd9Sstevel@tonic-gate exit(EX_ERROR); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate /* Set up */ 2187c478bd9Sstevel@tonic-gate exitcd = EX_OK; 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate /* -d on the command line ? */ 2227c478bd9Sstevel@tonic-gate if (d_seen) { 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * Determine case (removing a device group or members 2267c478bd9Sstevel@tonic-gate * of that device group. 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate if (nmems == 0) { 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate /* putdgrp -d dgroup */ 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate /* Attempt to remove the specified device */ 2347c478bd9Sstevel@tonic-gate if (!(_rmdgrptabrec(dgroup))) switch(errno) { 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate /* 2377c478bd9Sstevel@tonic-gate * EINVAL indicates that the named device-group was 2387c478bd9Sstevel@tonic-gate * not found in the device-group table. 2397c478bd9Sstevel@tonic-gate */ 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate case EINVAL: 2427c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRP, dgroup); 2437c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 2447c478bd9Sstevel@tonic-gate exitcd = EX_NODGRP; 2457c478bd9Sstevel@tonic-gate break; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* 2487c478bd9Sstevel@tonic-gate * ENOENT indicates that the device-group table can't 2497c478bd9Sstevel@tonic-gate * be found. 2507c478bd9Sstevel@tonic-gate */ 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate case ENOENT: 2537c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath()); 2547c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 2557c478bd9Sstevel@tonic-gate exitcd = EX_DGROUP; 2567c478bd9Sstevel@tonic-gate break; 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /* 2597c478bd9Sstevel@tonic-gate * EACCES indicates that there was a problem reading the 2607c478bd9Sstevel@tonic-gate * old device-group table or creating the new table. If the 2617c478bd9Sstevel@tonic-gate * old table is readable, assume that we can't create the 2627c478bd9Sstevel@tonic-gate * new table. Otherwise, assume that the old table isn't 2637c478bd9Sstevel@tonic-gate * accessible. 2647c478bd9Sstevel@tonic-gate */ 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate case EACCES: 2677c478bd9Sstevel@tonic-gate p = _dgrptabpath(); 2687c478bd9Sstevel@tonic-gate if (access(p, R_OK) == 0) 2697c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKTAB, p); 2707c478bd9Sstevel@tonic-gate else 2717c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p); 2727c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 2737c478bd9Sstevel@tonic-gate exitcd = EX_DGROUP; 2747c478bd9Sstevel@tonic-gate break; 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate /* 2777c478bd9Sstevel@tonic-gate * Some strange problem... 2787c478bd9Sstevel@tonic-gate */ 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate default: 2817c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_INTERNAL, errno); 2827c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 2837c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate } /* End switch */ 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate else { 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate /* putdgrp -d dgroup device [device [...]] */ 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate /* 2927c478bd9Sstevel@tonic-gate * Attempt to remove the specified devices from the 2937c478bd9Sstevel@tonic-gate * specified device-group. 2947c478bd9Sstevel@tonic-gate */ 2957c478bd9Sstevel@tonic-gate if (!(_rmdgrpmems(dgroup, &argv[optind], &plist))) switch(errno) { 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate /* 2987c478bd9Sstevel@tonic-gate * ENODEV indicates that a named device was not part 2997c478bd9Sstevel@tonic-gate * of the specified device group. 3007c478bd9Sstevel@tonic-gate */ 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate case ENODEV: 3037c478bd9Sstevel@tonic-gate exitcd = EX_NOMEM; 3047c478bd9Sstevel@tonic-gate for (; *plist; plist++) { 3057c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOTAMEM, *plist); 3067c478bd9Sstevel@tonic-gate stdmsg(MM_RECOVER, lbl, MM_WARNING, msg); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate break; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate /* 3117c478bd9Sstevel@tonic-gate * EINVAL indicates that the named device-group is not 3127c478bd9Sstevel@tonic-gate * defined in the device-group table. 3137c478bd9Sstevel@tonic-gate */ 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate case EINVAL: 3167c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRP, dgroup); 3177c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3187c478bd9Sstevel@tonic-gate exitcd = EX_NODGRP; 3197c478bd9Sstevel@tonic-gate break; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate /* 3227c478bd9Sstevel@tonic-gate * ENOENT indicates that the device table can't 3237c478bd9Sstevel@tonic-gate * be found. 3247c478bd9Sstevel@tonic-gate */ 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate case ENOENT: 3277c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath()); 3287c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3297c478bd9Sstevel@tonic-gate exitcd = EX_DGROUP; 3307c478bd9Sstevel@tonic-gate break; 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate /* 3337c478bd9Sstevel@tonic-gate * EACCES indicates that there was a problem reading the 3347c478bd9Sstevel@tonic-gate * old device table or creating the new table. If the 3357c478bd9Sstevel@tonic-gate * old table is readable, assume that we can't create the 3367c478bd9Sstevel@tonic-gate * new table. Otherwise, assume that the old table isn't 3377c478bd9Sstevel@tonic-gate * accessible. 3387c478bd9Sstevel@tonic-gate */ 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate case EACCES: 3417c478bd9Sstevel@tonic-gate p = _dgrptabpath(); 3427c478bd9Sstevel@tonic-gate if (access(p, R_OK) == 0) 3437c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKTAB, p); 3447c478bd9Sstevel@tonic-gate else 3457c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p); 3467c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3477c478bd9Sstevel@tonic-gate exitcd = EX_DGROUP; 3487c478bd9Sstevel@tonic-gate break; 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate /* 3517c478bd9Sstevel@tonic-gate * Some strange problem... 3527c478bd9Sstevel@tonic-gate */ 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate default: 3557c478bd9Sstevel@tonic-gate (void) sprintf(msg, E_INTERNAL, errno); 3567c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3577c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate } /* End switch */ 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate } /* End "putdgrp -d device attr [...]" case */ 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate } /* End -d case */ 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate else { 3677c478bd9Sstevel@tonic-gate /* Standard case (no -d on the command) */ 3687c478bd9Sstevel@tonic-gate if (!(_adddgrptabrec(argv[optind], &argv[optind+1]))) switch(errno) { 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate /* 3717c478bd9Sstevel@tonic-gate * ENOENT indicates that the device-group table does not exist. 3727c478bd9Sstevel@tonic-gate */ 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate case ENOENT: 3757c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath()); 3767c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3777c478bd9Sstevel@tonic-gate exitcd = EX_DGROUP; 3787c478bd9Sstevel@tonic-gate break; 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate /* 3817c478bd9Sstevel@tonic-gate * EACCES indicates that the device-group table could not be 3827c478bd9Sstevel@tonic-gate * opened or the new device-group table could not be created. 3837c478bd9Sstevel@tonic-gate */ 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate case EACCES: 3867c478bd9Sstevel@tonic-gate p = _dgrptabpath(); 3877c478bd9Sstevel@tonic-gate if (access(p, R_OK) == 0) 3887c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKTAB, p); 3897c478bd9Sstevel@tonic-gate else 3907c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p); 3917c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3927c478bd9Sstevel@tonic-gate exitcd = EX_DGROUP; 3937c478bd9Sstevel@tonic-gate break; 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* 3967c478bd9Sstevel@tonic-gate * Some strange error (memory?) 3977c478bd9Sstevel@tonic-gate */ 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate default: 4007c478bd9Sstevel@tonic-gate (void) sprintf(msg, E_INTERNAL, errno); 4017c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 4027c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 4037c478bd9Sstevel@tonic-gate } 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate /* Done. Return exit code (determined above) */ 4077c478bd9Sstevel@tonic-gate return(exitcd); 4087c478bd9Sstevel@tonic-gate } /* main() */ 409