Print this page
NEX-9532 NDMP: readdir errors when file/directory has special characters
Reviewed by: Peer Dampmann <peer.dampmann@nexenta.com>
Reviewed by: Alexander Eremin <alexander.eremin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-2990 ndmpd dumping core when used with ndmpcopy
NEX-2911 NDMP logging should use syslog and is too chatty
@@ -1,8 +1,7 @@
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
/*
* BSD 3 Clause License
*
@@ -34,10 +33,13 @@
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
+/* Copyright 2017 Nexenta Systems, Inc. All rights reserved. */
+
+#include <syslog.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
@@ -226,11 +228,11 @@
for (x = 0; sels[x] != NULL; x++) {
if (strcmp(sels[x], " ")) {
*pos = x;
(void) strlcpy(longname, sels[x], TLM_MAX_PATH_NAME);
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"to replace hardlink name [%s], pos [%d]",
longname, *pos);
return (rs_new_name(rnp, name, *pos, longname));
}
@@ -267,11 +269,11 @@
boolean_t is_long_name = FALSE;
char *longlink;
char *hugename;
longlong_t huge_size = 0; /* size of a HUGE file */
long acl_spot; /* any ACL info on the next volume */
- long file_size; /* size of file to restore */
+ long file_size = 0; /* size of file to restore */
long size_left = 0; /* need this after volume change */
int last_action = 0; /* what we are doing at EOT */
boolean_t multi_volume = FALSE; /* is this a multi-volume switch ? */
int chk_rv; /* scratch area */
@@ -335,14 +337,14 @@
lnk_end = 0;
*longlink = '\0';
(void) memset(acls, 0, sizeof (tlm_acls_t));
if (IS_SET(flags, RSFLG_OVR_ALWAYS)) {
acls->acl_overwrite = TRUE;
- NDMP_LOG(LOG_DEBUG, "RSFLG_OVR_ALWAYS");
+ syslog(LOG_DEBUG, "RSFLG_OVR_ALWAYS");
} else if (IS_SET(flags, RSFLG_OVR_UPDATE)) {
acls->acl_update = TRUE;
- NDMP_LOG(LOG_DEBUG, "RSFLG_OVR_UPDATE");
+ syslog(LOG_DEBUG, "RSFLG_OVR_UPDATE");
}
/*
* work
*/
@@ -381,11 +383,11 @@
/* used to make up hardlink_tmp_name */
static int hardlink_tmp_idx = 0;
if (multi_volume) {
- NDMP_LOG(LOG_DEBUG, "multi_volume %c %d",
+ syslog(LOG_DEBUG, "multi_volume %c %d",
last_action, size_left);
/*
* the previous volume is out of data
* and is back in the rack, a new tape
@@ -432,17 +434,17 @@
*/
chk_rv = tlm_vfy_tar_checksum(tar_hdr);
if (chk_rv == 0) {
/* one of the end of tar file marks */
if (++nzerohdr >= 2) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"nzerohdr %d, breaking",
nzerohdr);
/* end of tar file */
break;
}
- NDMP_LOG(LOG_DEBUG, "nzerohdr %d, continuing",
+ syslog(LOG_DEBUG, "nzerohdr %d, continuing",
nzerohdr);
continue;
} else if (chk_rv < 0) {
nzerohdr = 0;
/* skip this record */
@@ -482,16 +484,10 @@
acl_spot = 0;
last_action = tar_hdr->th_linkflag;
}
}
- NDMP_LOG(LOG_DEBUG, "n [%s] f [%c] s %lld m %o u %d g %d t %d",
- tar_hdr->th_name, tar_hdr->th_linkflag,
- acls->acl_attr.st_size, acls->acl_attr.st_mode,
- acls->acl_attr.st_uid, acls->acl_attr.st_gid,
- acls->acl_attr.st_mtime);
-
/*
* If the restore is running using DAR we should check for
* extended attribute entries
*/
if (dar_recovered &&
@@ -518,11 +514,11 @@
hardlink_done = !hardlink_q_get(hardlink_q,
hardlink_inode, 0, &hardlink_target);
}
if (hardlink_done) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"found hardlink, inode = %u, target = [%s]",
hardlink_inode,
hardlink_target? hardlink_target : "--");
/* create a hardlink to hardlink_target */
@@ -547,11 +543,11 @@
}
} else {
nmp = rs_new_name(rnp, name, pos,
file_name);
if (!nmp) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"can't make name for %s",
longname);
}
}
@@ -567,17 +563,17 @@
if (erc == 0) {
(void)
tlm_entry_restored(
job_stats,
file_name, pos);
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"restored %s -> %s",
nmp,
hardlink_target);
}
} else {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"no target for hardlink %s",
nmp);
}
name[0] = 0;
@@ -688,15 +684,15 @@
nmp = name;
hardlink_tmp_idx++;
hardlink_tmp_file = 1;
want_this_file = TRUE;
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"To restore temp hardlink file %s.",
nmp);
} else {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"No tmplink_dir specified.");
}
}
rv = restore_file(&fp, nmp, file_size,
@@ -716,11 +712,11 @@
* to locate the data records.
*/
if (is_hardlink && !DAR) {
if (hardlink_q_add(hardlink_q, hardlink_inode,
0, nmp, hardlink_tmp_file))
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"failed to add (%u, %s) to HL q",
hardlink_inode, nmp);
}
/* remove / reverse the temporary stuff */
@@ -747,13 +743,10 @@
}
}
if (rv != 0)
continue;
- NDMP_LOG(LOG_DEBUG, "sizeleft %s %d, %lld", longname,
- size_left, huge_size);
-
if (want_this_file) {
job_stats->js_bytes_total += file_size;
job_stats->js_files_total++;
}
@@ -769,11 +762,11 @@
/*
* Add an entry to hardlink_q to record
* this hardlink.
*/
if (is_hardlink) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Restored hardlink file %s",
nmp);
if (DAR) {
(void) hardlink_q_add(
@@ -805,12 +798,12 @@
case LF_SYMLINK:
file_name = (*longname == 0) ? thname_buf :
longname;
link_name = (*longlink == 0) ?
tar_hdr->th_linkname : longlink;
- NDMP_LOG(LOG_DEBUG, "file_name[%s]", file_name);
- NDMP_LOG(LOG_DEBUG, "link_name[%s]", link_name);
+ syslog(LOG_DEBUG, "file_name[%s]", file_name);
+ syslog(LOG_DEBUG, "link_name[%s]", link_name);
if (is_file_wanted(file_name, sels, exls, flags,
&mchtype, &pos)) {
nmp = rs_new_name(rnp, name, pos, file_name);
if (nmp) {
erc = create_sym_link(nmp, link_name,
@@ -918,11 +911,11 @@
file_size = max(0, file_size);
size_left = get_long_name(lib, drv, file_size, longlink,
&lnk_end, local_commands);
if (size_left != 0)
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"fsize %d sleft %d lnkend %d",
file_size, size_left, lnk_end);
break;
case LF_LONGNAME:
file_size = min(file_size,
@@ -930,11 +923,11 @@
file_size = max(0, file_size);
size_left = get_long_name(lib, drv, file_size, longname,
&nm_end, local_commands);
if (size_left != 0)
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"fsize %d sleft %d nmend %d",
file_size, size_left, nm_end);
is_long_name = TRUE;
break;
case LF_ACL:
@@ -996,10 +989,11 @@
char *dir; /* where to restore the files */
char job[TLM_MAX_BACKUP_JOB_NAME+1];
/* the restore job name */
int erc; /* error return codes */
int flags;
+ int i;
struct rs_name_maker rn;
tlm_commands_t *commands;
tlm_cmd_t *local_commands;
char *list = NULL;
@@ -1025,28 +1019,34 @@
* do not test for "dir" having no string, since that
* is a legal condition. Restore to origional location
* will not have a restore directory.
*/
if (*job == '\0') {
- NDMP_LOG(LOG_DEBUG, "No job defined");
+ syslog(LOG_DEBUG, "No job defined");
local_commands->tc_reader = TLM_STOP;
free(dir);
(void) pthread_barrier_wait(&argp->ba_barrier);
return (-1);
}
- sels = argp->ba_sels;
+ sels = ndmp_malloc(sizeof (char *) * (argp->ba_count + 1));
+ /* One extra for NULL terminate */
if (sels == NULL) {
local_commands->tc_reader = TLM_STOP;
free(dir);
(void) pthread_barrier_wait(&argp->ba_barrier);
return (-1);
}
+
+ (void) memset(sels, 0, (argp->ba_count + 1) * sizeof (char *));
+ for (i = 0; i < argp->ba_count; i++) {
+ sels[i] = argp->ba_sels[i];
+ }
+
exls = &list;
tlm_log_list("selections", sels);
- tlm_log_list("exclusions", exls);
if (wildcard_enabled())
flags |= RSFLG_MATCH_WCARD;
local_commands->tc_ref++;
@@ -1063,21 +1063,18 @@
rn.rn_nlp = dir;
/*
* work
*/
- NDMP_LOG(LOG_DEBUG, "start restore job %s", job);
erc = tar_getdir(commands, local_commands, job_stats, &rn, 1, 1,
sels, exls, flags, 0, NULL, NULL);
/*
* teardown
*/
- NDMP_LOG(LOG_DEBUG, "end restore job %s", job);
tlm_un_ref_job_stats(job);
tlm_release_list(sels);
- tlm_release_list(exls);
commands->tcs_writer_count--;
local_commands->tc_reader = TLM_STOP;
tlm_release_reader_writer_ipc(local_commands);
free(dir);
@@ -1102,11 +1099,11 @@
if (*cp == '\0' || *cp == '/') {
c = *cp;
*cp = '\0';
if (lstat64(dir, &st) < 0)
if (mkdir(dir, 0777) < 0) {
- NDMP_LOG(LOG_DEBUG, "Error %d"
+ syslog(LOG_ERR, "Error %d"
" creating directory %s",
errno, dir);
*cp = c;
return (errno);
}
@@ -1127,11 +1124,11 @@
int rv;
char *cp;
struct stat64 st;
if (!path || !*path) {
- NDMP_LOG(LOG_DEBUG, "Invalid argument");
+ syslog(LOG_ERR, "Invalid argument");
return (-1);
}
cp = strrchr(path, '/');
if (cp)
@@ -1167,15 +1164,14 @@
int ret, rv;
*size_left = 0;
if (!real_name) {
if (want_this_file) {
- NDMP_LOG(LOG_DEBUG, "No file name but wanted!");
+ syslog(LOG_DEBUG, "No file name but wanted!");
want_this_file = FALSE;
}
- } else
- NDMP_LOG(LOG_DEBUG, "new file[%s]", real_name);
+ }
/*
* OK, some FM is creeping in here ...
* int *fp is used to keep the
* backup file channel open through
@@ -1225,11 +1221,11 @@
if (want_this_file) {
*fp = open(real_name, O_CREAT | O_TRUNC | O_WRONLY,
S_IRUSR | S_IWUSR);
if (*fp == -1) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Could not open %s for restore: %d",
real_name, errno);
job_stats->js_errors++;
want_this_file = FALSE;
/*
@@ -1268,29 +1264,29 @@
error = 0;
rec = get_read_buffer(size, &error, &actual_size,
local_commands);
if (actual_size <= 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"RESTORE WRITER> error %d, actual_size %d",
error, actual_size);
/* no more data for this file for now */
job_stats->js_bytes_in_file = 0;
*size_left = size;
return (0);
} else if (error) {
- NDMP_LOG(LOG_DEBUG, "Error %d in file [%s]",
+ syslog(LOG_ERR, "Error %d in file [%s]",
error, local_commands->tc_file_name);
break;
}
write_size = min(size, actual_size);
if (want_this_file) {
ret = write(*fp, rec, write_size);
if (ret < 0) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Write error %d for file [%s]", errno,
local_commands->tc_file_name);
job_stats->js_errors++;
if (ERROR_IS_FATAL(errno)) {
rv = errno;
@@ -1298,11 +1294,11 @@
}
} else {
NS_ADD(wdisk, ret);
NS_INC(wfile);
if (ret < write_size) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Partial write for file [%s]",
local_commands->tc_file_name);
}
}
}
@@ -1398,29 +1394,27 @@
char *xattrname;
int actual_size;
int error;
if (!fname) {
- NDMP_LOG(LOG_DEBUG, "No file name but wanted!");
- } else {
- NDMP_LOG(LOG_DEBUG, "new xattr[%s]", fname);
+ syslog(LOG_DEBUG, "No file name but wanted!");
}
error = 0;
xhdr = (struct xattr_hdr *)get_read_buffer(size, &error,
&actual_size, local_commands);
if (xhdr == NULL || error != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Could not read xattr [%s:%s] for restore. ",
name, fname);
job_stats->js_errors++;
return (0);
}
/* Check extended attribute header */
if (strcmp(xhdr->h_version, XATTR_ARCH_VERS) != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Unrecognized header format [%s]", xhdr->h_version);
return (0);
}
xbuf = (struct xattr_buf *)(((char *)xhdr) + sizeof (struct xattr_hdr));
@@ -1430,11 +1424,11 @@
if (*fp == 0) {
int fd;
fd = attropen(name, xattrname, O_CREAT | O_RDWR, 0755);
if (fd == -1) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Could not open xattr [%s:%s] for restore err=%d.",
name, xattrname, errno);
job_stats->js_errors++;
return (0);
}
@@ -1445,11 +1439,11 @@
/* Get the actual extended attribute file */
tar_hdr = (tlm_tar_hdr_t *)get_read_buffer(sizeof (*tar_hdr),
&error, &actual_size, local_commands);
if (tar_hdr == NULL || error != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Could not read xattr data [%s:%s] for restore. ",
fname, xattrname);
job_stats->js_errors++;
return (0);
}
@@ -1457,14 +1451,10 @@
acls->acl_attr.st_size = oct_atoi(tar_hdr->th_size);
acls->acl_attr.st_uid = oct_atoi(tar_hdr->th_uid);
acls->acl_attr.st_gid = oct_atoi(tar_hdr->th_gid);
acls->acl_attr.st_mtime = oct_atoi(tar_hdr->th_mtime);
- NDMP_LOG(LOG_DEBUG, "xattr_hdr: %s size %d mode %06o uid %d gid %d",
- xattrname, acls->acl_attr.st_size, acls->acl_attr.st_mode,
- acls->acl_attr.st_uid, acls->acl_attr.st_gid);
-
size = acls->acl_attr.st_size;
while (size > 0 && local_commands->tc_writer == TLM_RESTORE_RUN) {
char *rec;
int write_size;
int sysattr_write = 0;
@@ -1475,25 +1465,25 @@
if ((actual_size < size) && sysattr_rw(xattrname)) {
rec = get_read_one_buf(rec, actual_size, size, &error,
local_commands);
if (rec == NULL) {
- NDMP_LOG(LOG_DEBUG, "Error %d in file [%s]",
+ syslog(LOG_ERR, "Error %d in file [%s]",
error, xattrname);
return (size);
}
actual_size = size;
sysattr_write = 1;
}
if (actual_size <= 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"RESTORE WRITER> error %d, actual_size %d",
error, actual_size);
return (size);
} else if (error) {
- NDMP_LOG(LOG_DEBUG, "Error %d in file [%s]",
+ syslog(LOG_ERR, "Error %d in file [%s]",
error, local_commands->tc_file_name);
break;
} else {
write_size = min(size, actual_size);
if ((write_size = write(*fp, rec, write_size)) < 0) {
@@ -1532,11 +1522,11 @@
found = FALSE;
for (i = 0; *list != NULL; list++, i++) {
cp = *list + strspn(*list, "/");
if (match(cp, name)) {
found = TRUE;
- NDMP_LOG(LOG_DEBUG, "exact_find> found[%s]", cp);
+ syslog(LOG_DEBUG, "exact_find> found[%s]", cp);
break;
}
}
return (found);
@@ -1551,18 +1541,18 @@
char tmp[TLM_MAX_PATH_NAME];
boolean_t rv;
if (IS_SET(flags, RSFLG_MATCH_WCARD)) {
if (!tlm_cat_path(tmp, parent, "*")) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"is_parent> path too long [%s]", parent);
rv = FALSE;
} else
rv = (match(tmp, child) != 0) ? TRUE : FALSE;
} else {
if (!tlm_cat_path(tmp, parent, "/")) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"is_parent> path too long [%s]", parent);
rv = FALSE;
} else
rv = (strncmp(tmp, child, strlen(tmp)) == 0) ?
TRUE : FALSE;
@@ -1590,11 +1580,11 @@
int flags,
int *mchtype,
int *pos)
{
char *p_sel;
- char *uc_name, *retry, *namep;
+ char *uc_name = NULL, *retry, *namep;
boolean_t found;
int i;
name_match_fp_t *cmp_fp;
if (name == NULL || sels == NULL || exls == NULL)
@@ -1608,11 +1598,11 @@
/*
* For empty selection, restore everything
*/
if (*sels == NULL || **sels == '\0') {
- NDMP_LOG(LOG_DEBUG, "is_file_wanted: Restore all");
+ syslog(LOG_DEBUG, "is_file_wanted: Restore all");
return (TRUE);
}
retry = ndmp_malloc(TLM_MAX_PATH_NAME);
if (retry == NULL)
@@ -1633,22 +1623,18 @@
}
(void) strlcpy(uc_name, namep, TLM_MAX_PATH_NAME);
(void) strupr(uc_name);
namep = uc_name;
}
- NDMP_LOG(LOG_DEBUG, "is_file_wanted> flg: 0x%x name: [%s]",
- flags, name);
for (i = 0; *sels != NULL; sels++, i++) {
p_sel = *sels + strspn(*sels, "/");
/*
* Try exact match.
*/
if ((*cmp_fp)(p_sel, namep)) {
- NDMP_LOG(LOG_DEBUG, "match1> pos: %d [%s][%s]",
- i, p_sel, name);
found = TRUE;
if (mchtype != NULL)
*mchtype = PM_EXACT;
break;
}
@@ -1656,11 +1642,11 @@
* Try "entry/" and the current selection. The
* current selection may be something like "<something>/".
*/
(void) tlm_cat_path(retry, namep, "/");
if ((*cmp_fp)(p_sel, retry)) {
- NDMP_LOG(LOG_DEBUG, "match2> pos %d [%s][%s]",
+ syslog(LOG_DEBUG, "match2> pos %d [%s][%s]",
i, p_sel, name);
found = TRUE;
if (mchtype != NULL)
*mchtype = PM_EXACT;
break;
@@ -1668,12 +1654,10 @@
/*
* If the following check returns true it means that the
* 'name' is an entry below the 'p_sel' hierarchy.
*/
if (is_parent(p_sel, namep, flags)) {
- NDMP_LOG(LOG_DEBUG, "parent1> pos %d [%s][%s]",
- i, p_sel, name);
found = TRUE;
if (mchtype != NULL)
*mchtype = PM_CHILD;
break;
}
@@ -1684,11 +1668,11 @@
* until the final entry matches with 'p_sel'. At that
* time the middle directories of the entry have been passed
* and they can't be restored.
*/
if (is_parent(namep, p_sel, flags)) {
- NDMP_LOG(LOG_DEBUG, "parent2> pos %d [%s][%s]",
+ syslog(LOG_DEBUG, "parent2> pos %d [%s][%s]",
i, p_sel, name);
found = TRUE;
if (mchtype != NULL)
*mchtype = PM_PARENT;
break;
@@ -1726,23 +1710,23 @@
int err;
int toread, actual_size, rec_size;
char *rec;
if (l <= 0 || d <= 0 || !lcmds || !mem) {
- NDMP_LOG(LOG_DEBUG, "Invalid argument");
+ syslog(LOG_ERR, "Invalid argument");
return (-1);
}
toread = len;
while (toread > 0) {
rec = get_read_buffer(toread, &err, &actual_size, lcmds);
if (actual_size <= 0) {
- NDMP_LOG(LOG_DEBUG, "err %d act_size %d detected",
+ syslog(LOG_ERR, "err %d act_size %d detected",
err, actual_size);
break;
} else if (err) {
- NDMP_LOG(LOG_DEBUG, "error %d reading data", err);
+ syslog(LOG_ERR, "error %d reading data", err);
return (-1);
}
rec_size = min(actual_size, toread);
(void) memcpy(mem, rec, rec_size);
mem += rec_size;
@@ -1764,11 +1748,11 @@
tlm_cmd_t *local_commands)
{
char *p_record, *value;
int rv;
- NDMP_LOG(LOG_DEBUG, "HUGE Record found: %d", recsize);
+ syslog(LOG_WARNING, "HUGE Record found: %d", recsize);
rv = 0;
if (recsize == 0) {
/*
* The humongus_file_header was written in a
@@ -1776,21 +1760,21 @@
* record was 0 before this fix. For backward compatiblity
* read only one RECORDSIZE-size block if the header.size
* field is 0. Otherwise the header.size field should show
* the length of the data of this header.
*/
- NDMP_LOG(LOG_DEBUG, "Old HUGE record found");
+ syslog(LOG_WARNING, "Old HUGE record found");
recsize = RECORDSIZE;
}
if (input_mem(lib, drv, local_commands, name, recsize) != recsize) {
rv = -1;
*size = 0;
*name = '\0';
- NDMP_LOG(LOG_DEBUG, "Error reading a HUGE file name");
+ syslog(LOG_ERR, "Error reading a HUGE file name");
} else {
- NDMP_LOG(LOG_DEBUG, "HUGE [%s]", name);
+ syslog(LOG_DEBUG, "HUGE [%s]", name);
p_record = name;
value = parse(&p_record, " ");
*size = atoll(value);
/*
@@ -1800,11 +1784,11 @@
* without check on the buffer size.
*/
(void) strlcpy(name, p_record, TLM_MAX_PATH_NAME);
}
- NDMP_LOG(LOG_DEBUG, "HUGE Record %lld [%s]", *size, name);
+ syslog(LOG_DEBUG, "HUGE Record %lld [%s]", *size, name);
return (rv);
}
/*
@@ -1818,11 +1802,11 @@
long *buf_spot,
tlm_cmd_t *local_commands)
{
int nread;
- NDMP_LOG(LOG_DEBUG, "LONGNAME Record found rs %d bs %d", recsize,
+ syslog(LOG_DEBUG, "LONGNAME Record found rs %d bs %d", recsize,
*buf_spot);
if (*buf_spot < 0)
*buf_spot = 0;
@@ -1829,16 +1813,16 @@
nread = input_mem(lib, drv, local_commands, name + *buf_spot,
recsize);
if (nread < 0) {
nread = recsize; /* return 0 as size left */
name[*buf_spot] = '\0';
- NDMP_LOG(LOG_ERR, "Error %d reading a long file name %s.",
+ syslog(LOG_ERR, "Error %d reading a long file name %s.",
nread, name);
} else {
*buf_spot += nread;
name[*buf_spot] = '\0';
- NDMP_LOG(LOG_DEBUG, "LONGNAME [%s]", name);
+ syslog(LOG_DEBUG, "LONGNAME [%s]", name);
}
return (recsize - nread);
}
@@ -1855,11 +1839,10 @@
/*
* Make sure all directories in this path exist, create them if
* needed.
*/
- NDMP_LOG(LOG_DEBUG, "new dir[%s]", dir);
erc = 0;
p = &dir[1];
do {
temp = *p;
@@ -1867,11 +1850,11 @@
*p = 0;
if (stat64(dir, &attr) < 0) {
if (mkdir(dir, 0777) != 0 && errno != EEXIST) {
erc = errno;
job_stats->js_errors++;
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Could not create directory %s: %d",
dir, errno);
break;
}
}
@@ -1902,11 +1885,11 @@
if (erc) {
/* Nothing to do if the destination already exists */
if (erc == EEXIST)
return (0);
job_stats->js_errors++;
- NDMP_LOG(LOG_DEBUG, "error %d (errno %d) hardlink [%s] to [%s]",
+ syslog(LOG_ERR, "error %d (errno %d) hardlink [%s] to [%s]",
erc, errno, name_new, name_old);
return (erc);
}
return (set_acl(name_new, acls));
}
@@ -1927,13 +1910,20 @@
return (erc);
st = &acls->acl_attr;
if (symlink(target, dst) != 0) {
erc = errno;
+ if (errno == EEXIST) {
+ erc = 0;
+ syslog(LOG_DEBUG,
+ "softlink [%s] to [%s] already existed",
+ dst, target);
+ } else {
job_stats->js_errors++;
- NDMP_LOG(LOG_DEBUG, "error %d softlink [%s] to [%s]",
+ syslog(LOG_ERR, "error %d softlink [%s] to [%s]",
errno, dst, target);
+ }
} else {
st->st_mode |= S_IFLNK;
erc = set_acl(dst, acls);
}
@@ -1962,11 +1952,11 @@
case LF_FIFO:
mode = S_IFIFO;
dev = 0;
break;
default:
- NDMP_LOG(LOG_ERR, "unsupported flag %d", flag);
+ syslog(LOG_ERR, "unsupported flag %d", flag);
return (-1);
}
/* Remove the old entry first */
if (rmdir(name) < 0) {
@@ -1973,11 +1963,11 @@
if (errno == ENOTDIR)
(void) unlink(name);
}
if (mknod(name, 0777 | mode, dev) != 0) {
job_stats->js_errors++;
- NDMP_LOG(LOG_DEBUG, "error %d mknod [%s] major"
+ syslog(LOG_ERR, "error %d mknod [%s] major"
" %d minor %d", errno, name, major, minor);
return (errno);
}
return (set_acl(name, acls));
}
@@ -2008,11 +1998,11 @@
bp = ((char *)&acls->acl_info) + *acl_spot;
nread = input_mem(lib, drv, local_commands, (void *)bp, file_size);
if (nread < 0) {
*acl_spot = 0;
(void) memset(acls, 0, sizeof (tlm_acls_t));
- NDMP_LOG(LOG_DEBUG, "Error reading ACL data");
+ syslog(LOG_ERR, "Error reading ACL data");
return (0);
}
*acl_spot += nread;
acls->acl_non_trivial = TRUE;
@@ -2023,11 +2013,11 @@
ndmp_set_eprivs_least(void)
{
priv_set_t *priv_set;
if ((priv_set = priv_allocset()) == NULL) {
- NDMP_LOG(LOG_ERR, "Out of memory.");
+ syslog(LOG_ERR, "Out of memory.");
return (-1);
}
priv_basicset(priv_set);
@@ -2045,11 +2035,11 @@
(void) priv_addset(priv_set, PRIV_SYS_DEVICES);
(void) priv_addset(priv_set, PRIV_SYS_MOUNT);
(void) priv_addset(priv_set, PRIV_SYS_CONFIG);
if (setppriv(PRIV_SET, PRIV_EFFECTIVE, priv_set) == -1) {
- NDMP_LOG(LOG_ERR, "Additional privileges required.");
+ syslog(LOG_ERR, "Additional privileges required.");
priv_freeset(priv_set);
return (-1);
}
priv_freeset(priv_set);
return (0);
@@ -2059,18 +2049,18 @@
ndmp_set_eprivs_all(void)
{
priv_set_t *priv_set;
if ((priv_set = priv_allocset()) == NULL) {
- NDMP_LOG(LOG_ERR, "Out of memory.");
+ syslog(LOG_ERR, "Out of memory.");
return (-1);
}
priv_fillset(priv_set);
if (setppriv(PRIV_SET, PRIV_EFFECTIVE, priv_set) != 0) {
- NDMP_LOG(LOG_ERR, "Additional privileges required.");
+ syslog(LOG_ERR, "Additional privileges required.");
return (-1);
}
priv_freeset(priv_set);
return (0);
}
@@ -2093,32 +2083,25 @@
if (!name || !acls)
return (0);
st = &acls->acl_attr;
- NDMP_LOG(LOG_DEBUG, "set_attr: %s uid %d gid %d uname %s gname %s "
- "mode %o", name, st->st_uid, st->st_gid, acls->uname, acls->gname,
- st->st_mode);
uid = st->st_uid;
if ((pwd = getpwnam(acls->uname)) != NULL) {
- NDMP_LOG(LOG_DEBUG, "set_attr: new uid %d old %d",
- pwd->pw_uid, uid);
uid = pwd->pw_uid;
}
gid = st->st_gid;
if ((grp = getgrnam(acls->gname)) != NULL) {
- NDMP_LOG(LOG_DEBUG, "set_attr: new gid %d old %d",
- grp->gr_gid, gid);
gid = grp->gr_gid;
}
erc = lchown(name, uid, gid);
if (erc != 0) {
erc = errno;
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Could not set uid or/and gid for file %s.", name);
}
if ((st->st_mode & (S_ISUID | S_ISGID)) != 0) {
/*
@@ -2125,11 +2108,11 @@
* Change effective privileges to 'all' which is required to
* change setuid bit for 'root' owned files. If fails, just
* send error to log file and proceed.
*/
if (ndmp_set_eprivs_all()) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Could not set effective privileges to 'all'.");
} else {
priv_all = TRUE;
}
}
@@ -2136,11 +2119,11 @@
if (!S_ISLNK(st->st_mode)) {
erc = chmod(name, st->st_mode);
if (erc != 0) {
erc = errno;
- NDMP_LOG(LOG_ERR, "Could not set correct file"
+ syslog(LOG_ERR, "Could not set correct file"
" permission for file %s: %d", name, errno);
}
tbuf.modtime = st->st_mtime;
tbuf.actime = st->st_atime;
@@ -2152,11 +2135,11 @@
* Give up the 'all' privileges for effective sets and go back
* to least required privileges. If fails, just send error to
* log file and proceed.
*/
if (ndmp_set_eprivs_least())
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Could not set least required privileges.");
}
return (erc);
}
@@ -2168,12 +2151,10 @@
set_acl(char *name, tlm_acls_t *acls)
{
int erc;
acl_t *aclp = NULL;
- if (name)
- NDMP_LOG(LOG_DEBUG, "set_acl: %s", name);
if (acls == NULL)
return (0);
/* Need a place to save real modification time */
@@ -2181,24 +2162,23 @@
if (ERROR_IS_FATAL(erc))
return (erc);
if (!acls->acl_non_trivial) {
(void) memset(acls, 0, sizeof (tlm_acls_t));
- NDMP_LOG(LOG_DEBUG, "set_acl: skipping trivial");
return (erc);
}
erc = acl_fromtext(acls->acl_info.attr_info, &aclp);
if (erc != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"TAPE RESTORE> acl_fromtext errno %d", erc);
}
if (aclp) {
erc = acl_set(name, aclp);
if (erc < 0) {
erc = errno;
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"TAPE RESTORE> acl_set errno %d", errno);
}
acl_free(aclp);
}
(void) memset(acls, 0, sizeof (tlm_acls_t));
@@ -2256,17 +2236,17 @@
{
char *rv;
rv = NULL;
if (!buf) {
- NDMP_LOG(LOG_DEBUG, "buf is NULL");
+ syslog(LOG_DEBUG, "buf is NULL");
} else if (!path) {
- NDMP_LOG(LOG_DEBUG, "path is NULL");
+ syslog(LOG_DEBUG, "path is NULL");
} else if (!rnp->rn_nlp) {
- NDMP_LOG(LOG_DEBUG, "rn_nlp is NULL [%s]", path);
+ syslog(LOG_DEBUG, "rn_nlp is NULL [%s]", path);
} else if (!tlm_cat_path(buf, rnp->rn_nlp, path)) {
- NDMP_LOG(LOG_DEBUG, "Path too long [%s][%s]",
+ syslog(LOG_DEBUG, "Path too long [%s][%s]",
rnp->rn_nlp, path);
} else
rv = buf;
return (rv);
@@ -2303,12 +2283,10 @@
slashp = bk_path + strlen(bk_path) - 1;
if (*slashp == '/')
(void) snprintf(pbuf, TLM_MAX_PATH_NAME, "%s%s", bk_path, p);
else
(void) snprintf(pbuf, TLM_MAX_PATH_NAME, "%s/%s", bk_path, p);
-
- NDMP_LOG(LOG_DEBUG, "old path [%s] new path [%s]", path, pbuf);
}
/*
* Iterate over ZFS metadata stored in the backup stream and use the callback
@@ -2406,20 +2384,20 @@
/* LINTED improper alignment */
mhpx = (ndmp_metadata_header_ext_t *)mhbuf;
if (mhpx->nh_major > META_HDR_MAJOR_VERSION) {
/* Major header mismatch */
- NDMP_LOG(LOG_ERR, "metadata header mismatch",
+ syslog(LOG_ERR, "metadata header mismatch",
"M%d != M%d", mhpx->nh_major,
META_HDR_MAJOR_VERSION);
free(mhbuf);
return (-1);
}
if (mhpx->nh_major == META_HDR_MAJOR_VERSION &&
mhpx->nh_minor > META_HDR_MINOR_VERSION) {
/* Minor header mismatch */
- NDMP_LOG(LOG_ERR, "Warning:"
+ syslog(LOG_ERR, "Warning:"
"metadata header mismatch m%d != m%d",
mhpx->nh_minor,
META_HDR_MINOR_VERSION);
continue;
}