sd = jcr->store_bsock;
+ get_backup_privileges(jcr, 0);
+
set_jcr_job_status(jcr, JS_Running);
Dmsg1(110, "bfiled: opened data connection %d to stored\n", sd->fd);
free_pool_memory(jcr->compress_buf);
jcr->compress_buf = NULL;
}
+ Dmsg1(110, "end blast_data stat=%d\n", stat);
return stat;
}
}
if (n == 1) { /* input waiting */
bnet_recv(sd); /* read it -- probably heartbeat from sd */
-/* Dmsg1(000, "Got %d from SD\n", sd->msglen); */
+ Dmsg1(100, "Got %d from SD\n", sd->msglen);
}
}
bnet_close(sd);
/* Wait for heartbeat thread to stop */
while (jcr->hb_bsock) {
+#ifndef HAVE_CYGWIN
+ /* Naturally, Cygwin 1.3.20 craps out on the following */
pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL); /* make heartbeat thread go away */
+#endif
bmicrosleep(0, 500);
}
}
found = TRUE; /* indicate command found */
if (!cmds[i].func(jcr)) { /* do command */
quit = TRUE; /* error or fully terminated, get out */
- Pmsg0(20, "Command error\n");
+ Pmsg0(20, "Command error or Job done.\n");
}
break;
}
jcr->sd_auth_key = bstrdup(sd_auth_key);
free_pool_memory(sd_auth_key);
if (jcr->use_win_backup_api) {
- SetServicePrivileges(jcr);
+ get_backup_privileges(jcr, 1 /* ignore_errors */);
}
Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key);
return bnet_fsend(dir, OKjob);
termstat);
sendit(msg, len, arg);
}
+ Dmsg0(200, "Begin status jcr loop.\n");
lock_jcr_chain();
for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) {
bstrftime(dt, sizeof(dt), njcr->start_time);
free_locked_jcr(njcr);
}
unlock_jcr_chain();
+ Dmsg0(200, "Begin status jcr loop.\n");
if (!found) {
len = Mmsg(&msg, _("No jobs running.\n"));
sendit(msg, len, arg);
break;
}
}
+ Dmsg0(200, "Begin bac_status jcr loop.\n");
lock_jcr_chain();
for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) {
if (njcr->JobId != 0) {
free_locked_jcr(njcr);
}
unlock_jcr_chain();
+ Dmsg0(200, "End bac_status jcr loop.\n");
strcpy(buf, termstat);
return buf;
}
// Usage string
const char BaculaUsageText[] = "Bacula [/run] [/kill] [/install] [/remove] [/about] [/status] [/events]\n";
+
+void LogErrorMsg(char *msg, char *fname, int lineno);
+#define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__)
// Create tray icon & menu if we're running as an app
bacMenu *menu = new bacMenu();
if (menu == NULL) {
-// LogErrorMsg("Could not create sys tray menu");
+// log_error_message("Could not create sys tray menu");
PostQuitMessage(0);
}
#include "winservice.h"
#include "wintray.h"
-// Error message logging
-void LogErrorMsg(char *message);
-#ifdef needed
-void SetServicePrivileges();
-#endif
// OS-SPECIFIC ROUTINES
if (RegisterService == NULL) {
MessageBox(NULL, "Registry service not found: Bacula service not started",
"Bacula Service", MB_OK);
- LogErrorMsg("Registry service not found");
+ log_error_message("Registry service not found");
break;
}
// Call the service control dispatcher with our entry table
if (!StartServiceCtrlDispatcher(dispatchTable)) {
- LogErrorMsg("StartServiceCtrlDispatcher failed.");
+ log_error_message("StartServiceCtrlDispatcher failed.");
}
break;
} /* end case */
g_hstatus = RegisterServiceCtrlHandler(BAC_SERVICENAME, ServiceCtrl);
if (g_hstatus == 0) {
- LogErrorMsg("RegisterServiceCtlHandler failed");
+ log_error_message("RegisterServiceCtlHandler failed");
MessageBox(NULL, "Contact Register Service Handler failure",
"Bacula service", MB_OK);
return;
45000)) { // Hint as to how long Bacula should have hung before you assume error
ReportStatus(SERVICE_STOPPED, g_error, 0);
- LogErrorMsg("ReportStatus failed 1");
+ log_error_message("ReportStatus STOPPED failed 1");
return;
}
NO_ERROR, // exit code
0)) { // wait hint
MessageBox(NULL, "Report Service failure", "Bacula Service", MB_OK);
- LogErrorMsg("ReportStatus failed 2");
+ log_error_message("ReportStatus RUNNING failed");
return 0;
}
return 0;
}
-#ifdef needed
-/*
- * Setup privileges we think we will need. We probably do not need
- * the SE_SECURITY_NAME, but since nothing seems to be working,
- * we get it hoping to fix the problems.
- */
-void SetServicePrivileges()
-{
- HANDLE hToken;
- TOKEN_PRIVILEGES tkp;
- // Get a token for this process.
- if (!OpenProcessToken(GetCurrentProcess(),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
- /* Forge on anyway */
- }
-
- // Get the LUID for the security privilege.
- LookupPrivilegeValue(NULL, SE_SECURITY_NAME, &tkp.Privileges[0].Luid);
-
- tkp.PrivilegeCount = 1; // one privilege to set
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
-
- // Get the security privilege for this process.
- AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES)NULL, (PDWORD)0);
-
- // Cannot test the return value of AdjustTokenPrivileges.
- if (GetLastError() != ERROR_SUCCESS) {
-// MessageBox(NULL, "Get security priv failed: AdjustTokePrivileges", "backup", MB_OK);
- }
-
- // Get the LUID for the backup privilege.
- LookupPrivilegeValue(NULL, SE_BACKUP_NAME, &tkp.Privileges[0].Luid);
-
- tkp.PrivilegeCount = 1; // one privilege to set
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
-
- // Get the backup privilege for this process.
- AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES)NULL, (PDWORD)0);
-
- // Cannot test the return value of AdjustTokenPrivileges.
- if (GetLastError() != ERROR_SUCCESS) {
-// MessageBox(NULL, "Get backup priv failed: AdjustTokePrivileges", "backup", MB_OK);
- }
-
- // Get the LUID for the restore privilege.
- LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &tkp.Privileges[0].Luid);
-
- tkp.PrivilegeCount = 1; // one privilege to set
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
-
- // Get the restore privilege for this process.
- AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES)NULL, (PDWORD)0);
-
- // Cannot test the return value of AdjustTokenPrivileges.
- if (GetLastError() != ERROR_SUCCESS) {
-// MessageBox(NULL, "Get restore priv failed: AdjustTokePrivileges", "restore", MB_OK);
- }
-
- CloseHandle(hToken);
-}
-
-#endif
// SERVICE STOP ROUTINE - post a quit message to the relevant thread
void ServiceStop()
strcat(servicecmd, "\\bacula-fd.conf");
} else {
- LogErrorMsg("Service commend length too long");
+ log_error_message("Service command length too long");
MessageBox(NULL, "Service command length too long. Service not registered.",
szAppName, MB_ICONEXCLAMATION | MB_OK);
return 0;
if (RegCreateKey(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion\\RunServices",
&runservices) != ERROR_SUCCESS) {
- LogErrorMsg("Cannot write System Registry");
+ log_error_message("Cannot write System Registry");
MessageBox(NULL, "The System Registry could not be updated - the Bacula service was not installed", szAppName, MB_ICONEXCLAMATION | MB_OK);
break;
}
// Attempt to add a Bacula key
if (RegSetValueEx(runservices, szAppName, 0, REG_SZ, (unsigned char *)servicecmd, strlen(servicecmd)+1) != ERROR_SUCCESS) {
RegCloseKey(runservices);
- LogErrorMsg("Cannot add Bacula key to System Registry");
+ log_error_message("Cannot add Bacula key to System Registry");
MessageBox(NULL, "The Bacula service could not be installed", szAppName, MB_ICONEXCLAMATION | MB_OK);
break;
}
// Open the default, local Service Control Manager database
hsrvmanager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hsrvmanager == NULL) {
- LogErrorMsg("OpenSCManager failed");
+ log_error_message("OpenSCManager failed");
MessageBox(NULL,
"The Service Control Manager could not be contacted - the Bacula service was not installed",
szAppName, MB_ICONEXCLAMATION | MB_OK);
NULL); // no password
if (hservice == NULL) {
CloseServiceHandle(hsrvmanager);
- LogErrorMsg("CreateService failed");
+ log_error_message("CreateService failed");
MessageBox(NULL,
"The Bacula service could not be installed",
szAppName, MB_ICONEXCLAMATION | MB_OK);
MB_ICONINFORMATION | MB_OK);
break;
default:
- LogErrorMsg("Unknow Windows OP Sys");
+ log_error_message("Unknown Windows System version");
MessageBox(NULL,
"Unknown Windows operating system.\n"
"Cannot install Bacula service.\n",
// Tell the SCM our new status
if (!(result = SetServiceStatus(g_hstatus, &g_srvstatus))) {
- LogErrorMsg("SetServiceStatus failed");
+ log_error_message("SetServiceStatus failed");
}
return result;
}
// Error reporting
-void LogErrorMsg(char *message)
+void LogErrorMsg(char *message, char *fname, int lineno)
{
char msgbuff[256];
HANDLE heventsrc;
// Use event logging to log the error
heventsrc = RegisterEventSource(NULL, BAC_SERVICENAME);
- sprintf(msgbuff, "%s error: %ld", BAC_SERVICENAME, g_error);
+ sprintf(msgbuff, "\n\n%s error: %ld at %s:%d",
+ BAC_SERVICENAME, g_error, fname, lineno);
strings[0] = msgbuff;
strings[1] = message;
strings[2] = msg;
#
LIBSRCS = find.c match.c find_one.c attibs.c create_file.c \
- bfile.c makepath.c save-cwd.c
+ bfile.c get_priv.c makepath.c save-cwd.c
LIBOBJS = find.o match.o find_one.o attribs.o create_file.o \
- bfile.o makepath.o save-cwd.o
+ bfile.o get_priv.o makepath.o save-cwd.o
.SUFFIXES: .c .o
.PHONY:
return STREAM_UNIX_ATTRIBUTES;
}
-void SetServicePrivileges(void *jcr)
- { }
-
-
#endif
cygwin_conv_to_win32_path(name, *win32_name);
}
-/*
- * Setup privileges we think we will need. We probably do not need
- * the SE_SECURITY_NAME, but since nothing seems to be working,
- * we get it hoping to fix the problems.
- */
-void SetServicePrivileges(void *jcr)
-{
- HANDLE hToken;
- TOKEN_PRIVILEGES tkp, tkpPrevious;
- DWORD cbPrevious = sizeof(TOKEN_PRIVILEGES);
- DWORD lerror;
- // Get a token for this process.
- if (!OpenProcessToken(GetCurrentProcess(),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
- win_error(jcr, "OpenProcessToken", GetLastError());
- /* Forge on anyway */
- }
-
- // Get the LUID for the security privilege.
- if (!LookupPrivilegeValue(NULL, SE_SECURITY_NAME, &tkp.Privileges[0].Luid)) {
- win_error(jcr, "LookupPrivilegeValue", GetLastError());
- }
-
- tkp.PrivilegeCount = 1;
- tkp.Privileges[0].Attributes = 0;
- /* Get the privilege */
- AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES),
- &tkpPrevious, &cbPrevious);
- lerror = GetLastError();
- if (lerror != ERROR_SUCCESS) {
- win_error(jcr, "AdjustTokenPrivileges get SECURITY_NAME", lerror);
- }
-
- tkpPrevious.PrivilegeCount = 1;
- tkpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
-
- /* Set the security privilege for this process. */
- AdjustTokenPrivileges(hToken, FALSE, &tkpPrevious, sizeof(TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL);
- lerror = GetLastError();
- if (lerror != ERROR_SUCCESS) {
- win_error(jcr, "AdjustTokenPrivileges set SECURITY_NAME", lerror);
- }
-
- // Get the LUID for the backup privilege.
- if (!LookupPrivilegeValue(NULL, SE_BACKUP_NAME, &tkp.Privileges[0].Luid)) {
- win_error(jcr, "LookupPrivilegeValue", GetLastError());
- }
-
- tkp.PrivilegeCount = 1;
- tkp.Privileges[0].Attributes = 0;
- /* Get the current privilege */
- AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES),
- &tkpPrevious, &cbPrevious);
- lerror = GetLastError();
- if (lerror != ERROR_SUCCESS) {
- win_error(jcr, "AdjustTokenPrivileges get BACKUP_NAME", lerror);
- }
-
- tkpPrevious.PrivilegeCount = 1;
- tkpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
-
- /* Set the backup privilege for this process. */
- AdjustTokenPrivileges(hToken, FALSE, &tkpPrevious, sizeof(TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL);
- lerror = GetLastError();
- if (lerror != ERROR_SUCCESS) {
- win_error(jcr, "AdjustTokenPrivileges set BACKUP_NAME", lerror);
- }
-
- // Get the LUID for the restore privilege.
- if (!LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &tkp.Privileges[0].Luid)) {
- win_error(jcr, "LookupPrivilegeValue", GetLastError());
- }
-
- tkp.PrivilegeCount = 1;
- tkp.Privileges[0].Attributes = 0;
- /* Get the privilege */
- AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES),
- &tkpPrevious, &cbPrevious);
- lerror = GetLastError();
- if (lerror != ERROR_SUCCESS) {
- win_error(jcr, "AdjustTokenPrivileges get RESTORE_NAME", lerror);
- }
-
- tkpPrevious.PrivilegeCount = 1;
- tkpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
-
- /* Set the security privilege for this process. */
- AdjustTokenPrivileges(hToken, FALSE, &tkpPrevious, sizeof(TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL);
- lerror = GetLastError();
- if (lerror != ERROR_SUCCESS) {
- win_error(jcr, "AdjustTokenPrivileges set RESTORE_NAME", lerror);
- }
- CloseHandle(hToken);
-}
-
-// MessageBox(NULL, "Get restore priv failed: AdjustTokePrivileges", "restore", MB_OK);
-
#endif /* HAVE_CYGWIN */
/*
* Status codes returned by create_file()
*/
-#define CF_SKIP 1 /* skip file (not newer or something) */
-#define CF_ERROR 2 /* error creating file */
-#define CF_EXTRACT 3 /* file created, data to extract */
-#define CF_CREATED 4 /* file created, no data to extract */
+#define CF_SKIP 1 /* skip file (not newer or something) */
+#define CF_ERROR 2 /* error creating file */
+#define CF_EXTRACT 3 /* file created, data to extract */
+#define CF_CREATED 4 /* file created, no data to extract */
/*
* NOTE!!! These go on the tape, so don't change them. If
* need be, add to them.
*/
-#define FT_LNKSAVED 1 /* hard link to file already saved */
-#define FT_REGE 2 /* Regular file but empty */
-#define FT_REG 3 /* Regular file */
-#define FT_LNK 4 /* Soft Link */
-#define FT_DIR 5 /* Directory */
-#define FT_SPEC 6 /* Special file -- chr, blk, fifo, sock */
-#define FT_NOACCESS 7 /* Not able to access */
-#define FT_NOFOLLOW 8 /* Could not follow link */
-#define FT_NOSTAT 9 /* Could not stat file */
-#define FT_NOCHG 10 /* Incremental option, file not changed */
-#define FT_DIRNOCHG 11 /* Incremental option, directory not changed */
-#define FT_ISARCH 12 /* Trying to save archive file */
-#define FT_NORECURSE 13 /* No recursion into directory */
-#define FT_NOFSCHG 14 /* Different file system, prohibited */
-#define FT_NOOPEN 15 /* Could not open directory */
-#define FT_RAW 16 /* Raw block device */
-#define FT_FIFO 17 /* Raw fifo device */
+#define FT_LNKSAVED 1 /* hard link to file already saved */
+#define FT_REGE 2 /* Regular file but empty */
+#define FT_REG 3 /* Regular file */
+#define FT_LNK 4 /* Soft Link */
+#define FT_DIR 5 /* Directory */
+#define FT_SPEC 6 /* Special file -- chr, blk, fifo, sock */
+#define FT_NOACCESS 7 /* Not able to access */
+#define FT_NOFOLLOW 8 /* Could not follow link */
+#define FT_NOSTAT 9 /* Could not stat file */
+#define FT_NOCHG 10 /* Incremental option, file not changed */
+#define FT_DIRNOCHG 11 /* Incremental option, directory not changed */
+#define FT_ISARCH 12 /* Trying to save archive file */
+#define FT_NORECURSE 13 /* No recursion into directory */
+#define FT_NOFSCHG 14 /* Different file system, prohibited */
+#define FT_NOOPEN 15 /* Could not open directory */
+#define FT_RAW 16 /* Raw block device */
+#define FT_FIFO 17 /* Raw fifo device */
/* Options saved in "flag" of ff packet */
-#define FO_MD5 0x001 /* Do MD5 checksum */
-#define FO_GZIP 0x002 /* Do Zlib compression */
-#define FO_NO_RECURSION 0x004 /* no recursion in directories */
-#define FO_MULTIFS 0x008 /* multiple file systems */
-#define FO_SPARSE 0x010 /* do sparse file checking */
-#define FO_IF_NEWER 0x020 /* replace if newer */
-#define FO_NOREPLACE 0x040 /* never replace */
-#define FO_READFIFO 0x080 /* read data from fifo */
-#define FO_SHA1 0x100 /* Do SHA1 checksum */
+#define FO_MD5 0x001 /* Do MD5 checksum */
+#define FO_GZIP 0x002 /* Do Zlib compression */
+#define FO_NO_RECURSION 0x004 /* no recursion in directories */
+#define FO_MULTIFS 0x008 /* multiple file systems */
+#define FO_SPARSE 0x010 /* do sparse file checking */
+#define FO_IF_NEWER 0x020 /* replace if newer */
+#define FO_NOREPLACE 0x040 /* never replace */
+#define FO_READFIFO 0x080 /* read data from fifo */
+#define FO_SHA1 0x100 /* Do SHA1 checksum */
/*
* Options saved in "options" of include list
#define OPT_compute_MD5 0x01 /* compute MD5 of file's data */
#define OPT_GZIP_compression 0x02 /* use GZIP compression */
#define OPT_no_recursion 0x04 /* no recursion in directories */
-#define OPT_multifs 0x08 /* multiple file systems */
-#define OPT_sparse 0x10 /* do sparse file checking */
+#define OPT_multifs 0x08 /* multiple file systems */
+#define OPT_sparse 0x10 /* do sparse file checking */
#define OPT_replace_if_newer 0x20 /* replace file if newer */
#define OPT_never_replace 0x40 /* never replace */
-#define OPT_read_fifo 0x80 /* read data from fifo (named pipe) */
+#define OPT_read_fifo 0x80 /* read data from fifo (named pipe) */
#define OPT_compute_SHA1 0x100 /* compute SHA1 of file's data */
struct s_included_file {
struct s_included_file *next;
- int options; /* backup options */
- int level; /* compression level */
- int len; /* length of fname */
- int pattern; /* set if pattern */
- char VerifyOpts[20]; /* Options for verify */
+ int options; /* backup options */
+ int level; /* compression level */
+ int len; /* length of fname */
+ int pattern; /* set if pattern */
+ char VerifyOpts[20]; /* Options for verify */
char fname[1];
};
#include <windows.h>
#define BF_CLOSED 0
-#define BF_READ 1 /* BackupRead */
-#define BF_WRITE 2 /* BackupWrite */
+#define BF_READ 1 /* BackupRead */
+#define BF_WRITE 2 /* BackupWrite */
/* Basic low level I/O file packet */
typedef struct s_bfile {
- int use_win_api; /* set if using WinAPI */
- int mode; /* set if file is open */
- HANDLE fh; /* Win32 file handle */
- int fid; /* fd if doing Unix style */
- LPVOID lpContext; /* BackupRead/Write context */
- POOLMEM *errmsg; /* error message buffer */
- DWORD rw_bytes; /* Bytes read or written */
- DWORD lerror; /* Last error code */
+ int use_win_api; /* set if using WinAPI */
+ int mode; /* set if file is open */
+ HANDLE fh; /* Win32 file handle */
+ int fid; /* fd if doing Unix style */
+ LPVOID lpContext; /* BackupRead/Write context */
+ POOLMEM *errmsg; /* error message buffer */
+ DWORD rw_bytes; /* Bytes read or written */
+ DWORD lerror; /* Last error code */
} BFILE;
#else
/* Basic low level I/O file packet */
typedef struct s_bfile {
- int fid; /* file id on Unix */
+ int fid; /* file id on Unix */
} BFILE;
#endif
* first argument to the find_files callback subroutine.
*/
typedef struct s_ff {
- char *fname; /* filename */
- char *link; /* link if file linked */
- POOLMEM *sys_fname; /* system filename */
- struct stat statp; /* stat packet */
- uint32_t FileIndex; /* FileIndex of this file */
- uint32_t LinkFI; /* FileIndex of main hard linked file */
- struct f_link *linked; /* Set if we are hard linked */
- int type; /* FT_ type from above */
- int flags; /* control flags */
- int ff_errno; /* errno */
- int incremental; /* do incremental save */
- BFILE bfd; /* Bacula file descriptor */
- time_t save_time; /* start of incremental time */
- int mtime_only; /* incremental on mtime_only */
- int dereference; /* follow links */
- int GZIP_level; /* compression level */
- int atime_preserve; /* preserve access times */
- int null_output_device; /* using null output device */
+ char *fname; /* filename */
+ char *link; /* link if file linked */
+ POOLMEM *sys_fname; /* system filename */
+ struct stat statp; /* stat packet */
+ uint32_t FileIndex; /* FileIndex of this file */
+ uint32_t LinkFI; /* FileIndex of main hard linked file */
+ struct f_link *linked; /* Set if we are hard linked */
+ int type; /* FT_ type from above */
+ int flags; /* control flags */
+ int ff_errno; /* errno */
+ int incremental; /* do incremental save */
+ BFILE bfd; /* Bacula file descriptor */
+ time_t save_time; /* start of incremental time */
+ int mtime_only; /* incremental on mtime_only */
+ int dereference; /* follow links */
+ int GZIP_level; /* compression level */
+ int atime_preserve; /* preserve access times */
+ int null_output_device; /* using null output device */
char VerifyOpts[20];
struct s_included_file *included_files_list;
struct s_excluded_file *excluded_files_list;
struct s_excluded_file *excluded_paths_list;
- struct f_link *linklist; /* hard linked files */
+ struct f_link *linklist; /* hard linked files */
} FF_PKT;
return handle_file(ff_pkt, pkt);
}
- Dmsg1(60, "File ----: %s\n", fname);
+ Dmsg1(300, "File ----: %s\n", fname);
/* Save current times of this directory in case we need to
* reset them because the user doesn't want them changed.
* or Incremental.
*/
if (ff_pkt->incremental && !S_ISDIR(ff_pkt->statp.st_mode)) {
- Dmsg1(100, "Non-directory incremental: %s\n", ff_pkt->fname);
+ Dmsg1(300, "Non-directory incremental: %s\n", ff_pkt->fname);
/* Not a directory */
if (ff_pkt->statp.st_mtime < ff_pkt->save_time
&& (ff_pkt->mtime_only ||
*/
/* from attribs.c */
-void encode_stat (char *buf, struct stat *statp, uint32_t LinkFI);
-void decode_stat (char *buf, struct stat *statp, uint32_t *LinkFI);
-int encode_attribsEx (void *jcr, char *attribsEx, FF_PKT *ff_pkt);
+void encode_stat (char *buf, struct stat *statp, uint32_t LinkFI);
+void decode_stat (char *buf, struct stat *statp, uint32_t *LinkFI);
+int encode_attribsEx (void *jcr, char *attribsEx, FF_PKT *ff_pkt);
int set_attributes(void *jcr, char *fname, char *ofile, char *lname,
- int type, int stream, struct stat *statp,
- char *attribsEx, BFILE *ofd);
-void SetServicePrivileges(void *jcr);
+ int type, int stream, struct stat *statp,
+ char *attribsEx, BFILE *ofd);
/* from create_file.c */
int create_file(void *jcr, char *fname, char *ofile, char *lname,
- int type, int stream, struct stat *statp,
- char *attribsEx, BFILE *ofd, int replace, int win_io);
+ int type, int stream, struct stat *statp,
+ char *attribsEx, BFILE *ofd, int replace, int win_io);
/* From find.c */
FF_PKT *init_find_files();
int file_is_excluded(FF_PKT *ff, char *file);
int file_is_included(FF_PKT *ff, char *file);
struct s_included_file *get_next_included_file(FF_PKT *ff,
- struct s_included_file *inc);
+ struct s_included_file *inc);
/* From find_one.c */
int find_one_file(JCR *jcr, FF_PKT *ff, int handle_file(FF_PKT *ff_pkt, void *hpkt),
- void *pkt, char *p, dev_t parent_device, int top_level);
+ void *pkt, char *p, dev_t parent_device, int top_level);
int term_find_one(FF_PKT *ff);
+/* From get_priv.c */
+void get_backup_privileges(void *jcr, int ignore_errors);
+
+
/* from makepath.c */
int make_path(void *jcr, const char *argpath, int mode,
- int parent_mode, uid_t owner, gid_t group,
- int preserve_existing, char *verbose_fmt_string);
+ int parent_mode, uid_t owner, gid_t group,
+ int preserve_existing, char *verbose_fmt_string);
/* from file_io.c */
ssize_t bread(BFILE *bfd, void *buf, size_t count);
-int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
-int bclose(BFILE *bfd);
+int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
+int bclose(BFILE *bfd);
ssize_t bread(BFILE *bfd, void *buf, size_t count);
ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
-off_t blseek(BFILE *bfd, off_t offset, int whence);
-int is_bopen(BFILE *bfd);
-void binit(BFILE *bfd, int use_win_api);
-char *berror(BFILE *bfd);
+off_t blseek(BFILE *bfd, off_t offset, int whence);
+int is_bopen(BFILE *bfd);
+void binit(BFILE *bfd, int use_win_api);
+char *berror(BFILE *bfd);
tv.tv_usec = 0;
for ( ;; ) {
switch(select(bsock->fd + 1, &fdset, NULL, NULL, &tv)) {
- case 0: /* timeout */
- bsock->b_errno = 0;
- return 0;
- case -1:
- bsock->b_errno = errno;
- if (errno == EINTR || errno == EAGAIN) {
- continue;
- }
- return -1; /* error return */
- default:
- bsock->b_errno = 0;
- return 1;
+ case 0: /* timeout */
+ bsock->b_errno = 0;
+ return 0;
+ case -1:
+ bsock->b_errno = errno;
+ if (errno == EINTR || errno == EAGAIN) {
+ continue;
+ }
+ return -1; /* error return */
+ default:
+ bsock->b_errno = 0;
+ return 1;
}
}
}
tv.tv_usec = 0;
for ( ;; ) {
switch(select(bsock->fd + 1, &fdset, NULL, NULL, &tv)) {
- case 0: /* timeout */
- bsock->b_errno = 0;
- return 0;
- case -1:
- bsock->b_errno = errno;
- return -1; /* error return */
- default:
- bsock->b_errno = 0;
- return 1;
+ case 0: /* timeout */
+ bsock->b_errno = 0;
+ return 0;
+ case -1:
+ bsock->b_errno = errno;
+ return -1; /* error return */
+ default:
+ bsock->b_errno = 0;
+ return 1;
}
}
}
BSOCK *
dup_bsock(BSOCK *osock)
{
- BSOCK *bsock = (BSOCK *) malloc(sizeof(BSOCK));
+ BSOCK *bsock = (BSOCK *)malloc(sizeof(BSOCK));
memcpy(bsock, osock, sizeof(BSOCK));
bsock->msg = get_pool_memory(PM_MESSAGE);
bsock->errmsg = get_pool_memory(PM_MESSAGE);
P(mutex);
jcr->use_count--; /* decrement use count */
- Dmsg2(200, "Decrement jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(200, "Dec jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
if (jcr->use_count > 0) { /* if in use */
V(mutex);
Dmsg2(200, "jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
void free_locked_jcr(JCR *jcr)
{
jcr->use_count--; /* decrement use count */
- Dmsg2(200, "Decrement jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(200, "Dec jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
if (jcr->use_count > 0) { /* if in use */
return;
}
for (jcr = jobs; jcr; jcr=jcr->next) {
if (jcr->JobId == JobId) {
jcr->use_count++;
- Dmsg2(200, "Increment jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(200, "Inc jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
break;
}
}
if (jcr->VolSessionId == SessionId &&
jcr->VolSessionTime == SessionTime) {
jcr->use_count++;
- Dmsg2(200, "Increment jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(200, "Inc jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
break;
}
}
for (jcr = jobs; jcr; jcr=jcr->next) {
if (strncmp(Job, jcr->Job, len) == 0) {
jcr->use_count++;
- Dmsg2(200, "Increment jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(200, "Inc jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
break;
}
}
for (jcr = jobs; jcr; jcr=jcr->next) {
if (strcmp(jcr->Job, Job) == 0) {
jcr->use_count++;
- Dmsg2(200, "Increment jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(200, "Inc jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
break;
}
}
}
if (rjcr) {
rjcr->use_count++;
- Dmsg1(200, "Increment jcr use_count=%d\n", rjcr->use_count);
+ Dmsg1(200, "Inc jcr use_count=%d\n", rjcr->use_count);
}
return rjcr;
}
FILE *con_fd = NULL; /* Console file descriptor */
brwlock_t con_lock; /* Console lock structure */
-#ifdef TRACE_FILE
FILE *trace_fd = NULL;
-#endif
/* Forward referenced functions */
MSGS *msgs;
BPIPE *bpipe;
- Dmsg2(200, "Enter dispatch_msg type=%d msg=%s\n", type, msg);
+ Dmsg2(800, "Enter dispatch_msg type=%d msg=%s\n", type, msg);
if (type == M_ABORT || type == M_ERROR_TERM) {
fputs(msg, stdout); /* print this here to INSURE that it is printed */
if (bit_is_set(type, d->msg_types)) {
switch (d->dest_code) {
case MD_CONSOLE:
- Dmsg1(400, "CONSOLE for following msg: %s", msg);
+ Dmsg1(800, "CONSOLE for following msg: %s", msg);
if (!con_fd) {
con_fd = fopen(con_fname, "a+");
- Dmsg0(200, "Console file not open.\n");
+ Dmsg0(800, "Console file not open.\n");
}
if (con_fd) {
Pw(con_lock); /* get write lock on console message file */
}
break;
case MD_SYSLOG:
- Dmsg1(400, "SYSLOG for collowing msg: %s\n", msg);
+ Dmsg1(800, "SYSLOG for collowing msg: %s\n", msg);
/*
* We really should do an openlog() here.
*/
syslog(LOG_DAEMON|LOG_ERR, "%s", msg);
break;
case MD_OPERATOR:
- Dmsg1(400, "OPERATOR for collowing msg: %s\n", msg);
+ Dmsg1(800, "OPERATOR for collowing msg: %s\n", msg);
mcmd = get_pool_memory(PM_MESSAGE);
if ((bpipe=open_mail_pipe(jcr, &mcmd, d))) {
int stat;
break;
case MD_MAIL:
case MD_MAIL_ON_ERROR:
- Dmsg1(400, "MAIL for following msg: %s", msg);
+ Dmsg1(800, "MAIL for following msg: %s", msg);
if (!d->fd) {
POOLMEM *name = get_pool_memory(PM_MESSAGE);
make_unique_mail_filename(jcr, &name, d);
fputs(msg, d->fd);
break;
case MD_FILE:
- Dmsg1(400, "FILE for following msg: %s", msg);
+ Dmsg1(800, "FILE for following msg: %s", msg);
if (!d->fd) {
d->fd = fopen(d->where, "w+");
if (!d->fd) {
fputs(msg, d->fd);
break;
case MD_APPEND:
- Dmsg1(400, "APPEND for following msg: %s", msg);
+ Dmsg1(800, "APPEND for following msg: %s", msg);
if (!d->fd) {
d->fd = fopen(d->where, "a");
if (!d->fd) {
fputs(msg, d->fd);
break;
case MD_DIRECTOR:
- Dmsg1(400, "DIRECTOR for following msg: %s", msg);
+ Dmsg1(800, "DIRECTOR for following msg: %s", msg);
if (jcr && jcr->dir_bsock && !jcr->dir_bsock->errors) {
jcr->dir_bsock->msglen = Mmsg(&(jcr->dir_bsock->msg),
}
break;
case MD_STDOUT:
- Dmsg1(400, "STDOUT for following msg: %s", msg);
+ Dmsg1(800, "STDOUT for following msg: %s", msg);
if (type != M_ABORT && type != M_ERROR_TERM) { /* already printed */
fputs(msg, stdout);
}
break;
case MD_STDERR:
- Dmsg1(400, "STDERR for following msg: %s", msg);
+ Dmsg1(800, "STDERR for following msg: %s", msg);
fputs(msg, stderr);
break;
default:
}
if (level <= debug_level) {
+#ifdef SEND_DMSG_TO_FILE
+ if (!trace_fd) {
+ bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory);
+ trace_fd = fopen(buf, "a+");
+ if (!trace_fd) {
+ Emsg2(M_ABORT, 0, _("Cannot open %s: ERR=%s\n"),
+ buf, strerror(errno));
+ }
+ }
+#endif
#ifdef FULL_LOCATION
if (details) {
len= sprintf(buf, "%s: %s:%d ", my_name, file, line);
bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr);
va_end(arg_ptr);
+#ifdef SEND_DMSG_TO_FILE
+ fputs(buf, trace_fd);
+ fflush(trace_fd);
+#else
fputs(buf, stdout);
+#endif
}
}
if (level <= debug_level) {
if (!trace_fd) {
- trace_fd = fopen("bacula.trace", "a+");
+ bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory);
+ trace_fd = fopen(buf, "a+");
if (!trace_fd) {
- Emsg1(M_ABORT, 0, _("Cannot open bacula.trace: ERR=%s\n"),
- strerror(errno));
+ Emsg2(M_ABORT, 0, _("Cannot open %s: ERR=%s\n"),
+ buf, strerror(errno));
}
}
char *job;
- Dmsg1(200, "Enter Jmsg type=%d\n", type);
+ Dmsg1(800, "Enter Jmsg type=%d\n", type);
msgs = NULL;
job = NULL;
#include "bits.h"
-#undef M_DEBUG
-#undef M_ABORT
-#undef M_FATAL
-#undef M_ERROR
-#undef M_WARNING
-#undef M_INFO
-#undef M_MOUNT
-#undef M_ERROR_TERM
-#undef M_TERM
-#undef M_RESTORED
+#undef M_DEBUG
+#undef M_ABORT
+#undef M_FATAL
+#undef M_ERROR
+#undef M_WARNING
+#undef M_INFO
+#undef M_MOUNT
+#undef M_ERROR_TERM
+#undef M_TERM
+#undef M_RESTORED
/*
* Most of these message levels are more or less obvious.
* and here are some of the details of where I am trying to
* head (in the process of changing the code) as of 15 June 2002.
*
- * M_ABORT Bacula immediately aborts and tries to produce a traceback
- * This is for really serious errors like segmentation fault.
+ * M_ABORT Bacula immediately aborts and tries to produce a traceback
+ * This is for really serious errors like segmentation fault.
* M_ERROR_TERM Bacula immediately terminates but no dump. This is for
* "obvious" serious errors like daemon already running or
- * cannot open critical file, ... where a dump is not wanted.
- * M_TERM Bacula daemon shutting down because of request (SIGTERM).
+ * cannot open critical file, ... where a dump is not wanted.
+ * M_TERM Bacula daemon shutting down because of request (SIGTERM).
*
* The remaining apply to Jobs rather than the daemon.
*
- * M_FATAL Bacula detected a fatal Job error. The Job will be killed,
- * but Bacula continues running.
- * M_ERROR Bacula detected a Job error. The Job will continue running
- * but the termination status will be error.
- * M_WARNING Job warning message.
- * M_INFO Job information message.
+ * M_FATAL Bacula detected a fatal Job error. The Job will be killed,
+ * but Bacula continues running.
+ * M_ERROR Bacula detected a Job error. The Job will continue running
+ * but the termination status will be error.
+ * M_WARNING Job warning message.
+ * M_INFO Job information message.
*
- * M_RESTORED An ls -l of each restored file.
+ * M_RESTORED An ls -l of each restored file.
*
*/
-#define M_DEBUG 1 /* debug message */
-#define M_ABORT 2 /* MUST abort immediately */
-#define M_FATAL 3 /* Fatal error, stopping job */
-#define M_ERROR 4 /* Error, but recoverable */
-#define M_WARNING 5 /* Warning message */
-#define M_INFO 6 /* Informational message */
-#define M_SAVED 7 /* Info on saved file */
-#define M_NOTSAVED 8 /* Info on notsaved file */
-#define M_SKIPPED 9 /* File skipped by option setting */
-#define M_MOUNT 10 /* Mount requests */
-#define M_ERROR_TERM 11 /* Error termination request (no dump) */
-#define M_TERM 12 /* Terminating daemon */
-#define M_RESTORED 13 /* ls -l of restored files */
+#define M_DEBUG 1 /* debug message */
+#define M_ABORT 2 /* MUST abort immediately */
+#define M_FATAL 3 /* Fatal error, stopping job */
+#define M_ERROR 4 /* Error, but recoverable */
+#define M_WARNING 5 /* Warning message */
+#define M_INFO 6 /* Informational message */
+#define M_SAVED 7 /* Info on saved file */
+#define M_NOTSAVED 8 /* Info on notsaved file */
+#define M_SKIPPED 9 /* File skipped by option setting */
+#define M_MOUNT 10 /* Mount requests */
+#define M_ERROR_TERM 11 /* Error termination request (no dump) */
+#define M_TERM 12 /* Terminating daemon */
+#define M_RESTORED 13 /* ls -l of restored files */
-#define M_MAX M_RESTORED /* keep this updated ! */
+#define M_MAX M_RESTORED /* keep this updated ! */
/* Define message destination structure */
/* *** FIXME **** where should be extended to handle multiple values */
typedef struct s_dest {
struct s_dest *next;
- int dest_code; /* destination (one of the MD_ codes) */
- int max_len; /* max mail line length */
- FILE *fd; /* file descriptor */
+ int dest_code; /* destination (one of the MD_ codes) */
+ int max_len; /* max mail line length */
+ FILE *fd; /* file descriptor */
char msg_types[nbytes_for_bits(M_MAX+1)]; /* message type mask */
- char *where; /* filename/program name */
- char *mail_cmd; /* mail command */
- POOLMEM *mail_filename; /* unique mail filename */
+ char *where; /* filename/program name */
+ char *mail_cmd; /* mail command */
+ POOLMEM *mail_filename; /* unique mail filename */
} DEST;
/* Message Destination values for dest field of DEST */
-#define MD_SYSLOG 1 /* send msg to syslog */
-#define MD_MAIL 2 /* email group of messages */
-#define MD_FILE 3 /* write messages to a file */
-#define MD_APPEND 4 /* append messages to a file */
-#define MD_STDOUT 5 /* print messages */
-#define MD_STDERR 6 /* print messages to stderr */
-#define MD_DIRECTOR 7 /* send message to the Director */
-#define MD_OPERATOR 8 /* email a single message to the operator */
-#define MD_CONSOLE 9 /* send msg to UserAgent or console */
-#define MD_MAIL_ON_ERROR 10 /* email messages if job errors */
+#define MD_SYSLOG 1 /* send msg to syslog */
+#define MD_MAIL 2 /* email group of messages */
+#define MD_FILE 3 /* write messages to a file */
+#define MD_APPEND 4 /* append messages to a file */
+#define MD_STDOUT 5 /* print messages */
+#define MD_STDERR 6 /* print messages to stderr */
+#define MD_DIRECTOR 7 /* send message to the Director */
+#define MD_OPERATOR 8 /* email a single message to the operator */
+#define MD_CONSOLE 9 /* send msg to UserAgent or console */
+#define MD_MAIL_ON_ERROR 10 /* email messages if job errors */
void d_msg(char *file, int line, int level, char *fmt,...);
for ( ;!quit; ) {
time_t timer_start, now;
- Dmsg0(200, "Top of for loop\n");
+ Dmsg0(200, "Top of watchdog loop\n");
watchdog_time = time(NULL); /* update timer */
}
unlock_jcr_chain();
+ Dmsg0(200, "Watchdog sleep.\n");
bmicrosleep(SLEEP_TIME, 0);
now = time(NULL);
#define SMCHECK
#define TRACE_FILE 1
+/* Turn this on ONLY if you want all Dmsg() to append to the
+ * trace file. Implemented mainly for Win32 ...
+ */
+/* #define SEND_DMSG_TO_FILE 1 */
+
/* Turn this on if you want to try the new Job semaphore code */
#define USE_SEMAPHORE