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]
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
27 * Utility functions used by the ipmgmtd daemon.
37 #include "ipmgmt_impl.h"
39 #define IPMGMT_BUFSIZ 1024
42 ipmgmt_log(int pri
, const char *fmt
, ...)
47 vsyslog(pri
, fmt
, alist
);
52 * Copy a source file to a new destination. The source file will be
53 * removed if rdonly is false (i.e., used when the source file resides
54 * on a read-only file system).
56 * Returns 0 on success and errno on failure.
59 ipmgmt_cpfile(const char *src
, const char *dst
, boolean_t rdonly
)
63 char buf
[IPMGMT_BUFSIZ
];
68 * Attempt to open the destination file first since we
69 * want to optimize for the case where it is read-only
70 * and will return EROFS.
72 if ((dfp
= fopen(dst
, "w+")) == NULL
)
76 * Require that the source file exists.
78 if (stat(src
, &statbuf
) != 0) {
83 if ((sfp
= fopen(src
, "r")) == NULL
) {
92 while (fgets(buf
, sizeof (buf
), sfp
) != NULL
&& errno
== 0) {
93 (void) fputs(buf
, dfp
);
99 else if (fflush(dfp
) == EOF
)
106 * If any error occurred, then remove the destination file.
114 * Make sure the file attributes are correct.
116 if (chmod(dst
, IPADM_FILE_MODE
) != 0 ||
117 chown(dst
, UID_NETADM
, GID_NETADM
) != 0) {
124 * If the source file does not reside on a read-only file system