From a60e37a435afd0b14441bdae15f63d2c34cb14dd Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 27 Jun 2004 11:23:25 +0000 Subject: [PATCH] Win32 fixes + resources array fix git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1447 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/console/console_conf.c | 2 +- bacula/src/dird/dird_conf.c | 2 +- bacula/src/filed/filed_conf.c | 2 +- bacula/src/filed/status.c | 49 +++++----- bacula/src/filed/win32/Makefile.in | 2 +- bacula/src/filed/win32/Makefile.mingw | 2 +- bacula/src/filed/win32/warn.ico | Bin 0 -> 766 bytes bacula/src/filed/win32/winmain.cpp | 3 +- bacula/src/filed/win32/winres.h | 5 +- bacula/src/filed/win32/winres.rc | 1 + bacula/src/filed/win32/winservice.cpp | 1 + bacula/src/filed/win32/wintray.cpp | 123 +++++++++++--------------- bacula/src/filed/win32/wintray.h | 19 ++-- bacula/src/jcr.h | 2 +- bacula/src/lib/bnet_server.c | 4 +- bacula/src/lib/jcr.c | 1 + bacula/src/stored/stored_conf.c | 2 +- 17 files changed, 106 insertions(+), 114 deletions(-) create mode 100644 bacula/src/filed/win32/warn.ico diff --git a/bacula/src/console/console_conf.c b/bacula/src/console/console_conf.c index 89c31d0705..4a377dfa66 100644 --- a/bacula/src/console/console_conf.c +++ b/bacula/src/console/console_conf.c @@ -47,7 +47,7 @@ */ int r_first = R_FIRST; int r_last = R_LAST; -static RES *sres_head[R_LAST - R_FIRST]; +static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; /* Forward referenced subroutines */ diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index fa8d41568f..18591c256f 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -50,7 +50,7 @@ */ int r_first = R_FIRST; int r_last = R_LAST; -static RES *sres_head[R_LAST - R_FIRST]; +static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; /* Imported subroutines */ diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index c4c62fe620..23d8e62780 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -51,7 +51,7 @@ */ int r_first = R_FIRST; int r_last = R_LAST; -static RES *sres_head[R_LAST - R_FIRST]; +static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 715a80af69..0c16b08460 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -306,7 +306,6 @@ static const char *level_to_str(int level) #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) #include -static char buf[100]; int bacstat = 0; struct s_win32_arg { @@ -325,8 +324,7 @@ static void win32_sendit(const char *msg, int len, void *marg) // when compiling with visual studio some strings are read-only // and cause access violations. So we creat a tmp copy. char *_msg = (char *)alloca(len); - strncpy(_msg, msg, len-1); - _msg[len-1] = 0; + bstrncpy(_msg, msg, len); msg = _msg; } SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg); @@ -346,45 +344,54 @@ void FillStatusBox(HWND hwnd, int idlist) do_status(win32_sendit, (void *)&arg); } -char *bac_status(int stat) +char *bac_status(char *buf, int buf_len) { JCR *njcr; const char *termstat = _("Bacula Idle"); struct s_last_job *job; + int stat = 0; /* Idle */ - bacstat = 0; if (!last_jobs) { - return _("Bacula Terminated"); + goto done; + } + Dmsg0(1000, "Begin bac_status jcr loop.\n"); + lock_jcr_chain(); + foreach_jcr(njcr) { + if (njcr->JobId != 0) { + stat = JS_Running; + termstat = _("Bacula Running"); + free_locked_jcr(njcr); + break; + } + free_locked_jcr(njcr); + } + unlock_jcr_chain(); + if (stat != 0) { + goto done; } if (last_jobs->size() > 0) { job = (struct s_last_job *)last_jobs->last(); + stat = job->JobStatus; switch (job->JobStatus) { case JS_Canceled: - bacstat = -1; termstat = _("Last Job Canceled"); break; case JS_ErrorTerminated: - bacstat = -1; termstat = _("Last Job Failed"); break; default: + if (job->Errors) { + termstat = _("Last Job had Errors"); + } break; } } - Dmsg0(1000, "Begin bac_status jcr loop.\n"); - lock_jcr_chain(); - foreach_jcr(njcr) { - if (njcr->JobId != 0) { - bacstat = 1; - termstat = _("Bacula Running"); - free_locked_jcr(njcr); - break; - } - free_locked_jcr(njcr); - } - unlock_jcr_chain(); Dmsg0(1000, "End bac_status jcr loop.\n"); - bstrncpy(buf, termstat, sizeof(buf)); +done: + bacstat = stat; + if (buf) { + bstrncpy(buf, termstat, sizeof(buf)); + } return buf; } diff --git a/bacula/src/filed/win32/Makefile.in b/bacula/src/filed/win32/Makefile.in index d25f21dd8a..d7b01e6b73 100755 --- a/bacula/src/filed/win32/Makefile.in +++ b/bacula/src/filed/win32/Makefile.in @@ -46,7 +46,7 @@ win32: winlib.a winlib.a: $(BACOBJS) winres.res ar rcs $@ $(BACOBJS) -winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico +winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico warn.ico windres $< -O coff -o $@ winmain.o: winmain.cpp winbacula.h diff --git a/bacula/src/filed/win32/Makefile.mingw b/bacula/src/filed/win32/Makefile.mingw index 978699c2d5..4a3e36ff77 100644 --- a/bacula/src/filed/win32/Makefile.mingw +++ b/bacula/src/filed/win32/Makefile.mingw @@ -46,7 +46,7 @@ win32: winlib.a winlib.a: $(BACOBJS) winres.res ar rcs $@ $(BACOBJS) -winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico +winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico warn.ico windres -DHAVE_MINGW $< -O coff -o $@ winmain.o: winmain.cpp winbacula.h diff --git a/bacula/src/filed/win32/warn.ico b/bacula/src/filed/win32/warn.ico new file mode 100644 index 0000000000000000000000000000000000000000..26e1d398bb446fb55d02635a2afa4dc8489e0587 GIT binary patch literal 766 zcmc&yu?~VT5Pd}wMy-RZwJeSret?0`a%lXrPEI8Lf}!Bzr^i}8{7j(2xG zt_gskN2wJU_YBxj+!GbCCJN-F^DxH1S_@EwbMuWqsmKI;hr~+B2^}GMgJ^Z|WmReI zCHMod)?U0X(bU3A=r8l85njIZqw`^OoUeCM>L8Q*@yo9M@*nkN z)Sq5mk0-Ev07VBZEd6pV?epeoi}rFf?O8>#=X~FHb*^L5Sr7&DMzd&MF??exz5s&v BWi|i+ literal 0 HcmV?d00001 diff --git a/bacula/src/filed/win32/winmain.cpp b/bacula/src/filed/win32/winmain.cpp index 625146ae20..6cbf0309e1 100755 --- a/bacula/src/filed/win32/winmain.cpp +++ b/bacula/src/filed/win32/winmain.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2003 Kern Sibbald and John Walker + Copyright (C) 2000-2004 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -18,7 +18,6 @@ This file is patterned after the VNC Win32 code by ATT - Copyright (2000) Kern E. Sibbald */ #ifndef HAVE_WIN32 diff --git a/bacula/src/filed/win32/winres.h b/bacula/src/filed/win32/winres.h index a1f52e9f26..66a84c1b86 100755 --- a/bacula/src/filed/win32/winres.h +++ b/bacula/src/filed/win32/winres.h @@ -7,7 +7,9 @@ #define IDI_IDLE 101 #define IDI_RUNNING 102 #define IDI_JOB_ERROR 103 -#define IDR_TRAYMENU 104 +#define IDI_JOB_WARNING 104 +#define IDR_TRAYMENU 105 +#define IDB_BACULABMP 106 #define IDC_LIST 1000 #define IDC_NONYET_LABEL 1006 @@ -42,4 +44,3 @@ #define IDD_EVENTS 203 -#define IDB_BACULABMP 106 diff --git a/bacula/src/filed/win32/winres.rc b/bacula/src/filed/win32/winres.rc index e4e997b141..3c19cc85ef 100644 --- a/bacula/src/filed/win32/winres.rc +++ b/bacula/src/filed/win32/winres.rc @@ -14,6 +14,7 @@ IDI_BACULA ICON DISCARDABLE "bacula.ico" IDI_IDLE ICON DISCARDABLE "idle.ico" IDI_RUNNING ICON DISCARDABLE "running.ico" IDI_JOB_ERROR ICON DISCARDABLE "error.ico" +IDI_JOB_WARNING ICON DISCARDABLE "warn.ico" ///////////////////////////////////////////////////////////////////////////// // diff --git a/bacula/src/filed/win32/winservice.cpp b/bacula/src/filed/win32/winservice.cpp index 2bac945a27..0111087d2f 100755 --- a/bacula/src/filed/win32/winservice.cpp +++ b/bacula/src/filed/win32/winservice.cpp @@ -38,6 +38,7 @@ #include +#undef PASCAL #include "winbacula.h" #include "winservice.h" #include "wintray.h" diff --git a/bacula/src/filed/win32/wintray.cpp b/bacula/src/filed/win32/wintray.cpp index 933e613573..3105220eed 100755 --- a/bacula/src/filed/win32/wintray.cpp +++ b/bacula/src/filed/win32/wintray.cpp @@ -25,7 +25,7 @@ // by Kern E. Sibbald. Many thanks to ATT and James Weatherall, // the original author, for providing an excellent template. // -// Copyright (2000-2003) Kern E. Sibbald +// Copyright 2000-2004, Kern E. Sibbald // @@ -41,6 +41,8 @@ // Header #include "wintray.h" +#include "bacula.h" +#include "jcr.h" // Constants #ifdef properties_implemented @@ -55,7 +57,7 @@ const UINT MENU_ADD_CLIENT_MSG = RegisterWindowMessage("Bacula.AddClient.Message const char *MENU_CLASS_NAME = "Bacula Tray Icon"; extern void terminate_filed(int sig); -extern char *bac_status(int stat); +extern char *bac_status(char *buf, int buf_len); extern int bacstat; // Implementation @@ -102,9 +104,10 @@ bacMenu::bacMenu() SetTimer(m_hwnd, 1, 5000, NULL); // Load the icons for the tray - m_idle_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_IDLE)); + m_idle_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_IDLE)); m_running_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_RUNNING)); - m_error_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_ERROR)); + m_error_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_ERROR)); + m_warn_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_WARNING)); // Load the popup menu m_hmenu = LoadMenu(hAppInstance, MAKEINTRESOURCE(IDR_TRAYMENU)); @@ -139,23 +142,42 @@ bacMenu::DelTrayIcon() void bacMenu::UpdateTrayIcon(int bacstat) { - (void *)bac_status(0); + (void *)bac_status(NULL, 0); SendTrayMsg(NIM_MODIFY, bacstat); } void bacMenu::SendTrayMsg(DWORD msg, int bacstat) { + struct s_last_job *job; + // Create the tray icon message m_nid.hWnd = m_hwnd; m_nid.cbSize = sizeof(m_nid); m_nid.uID = IDI_BACULA; // never changes after construction - if (bacstat == 0) + switch (bacstat) { + case 0: m_nid.hIcon = m_idle_icon; - else if (bacstat == 1) + break; + case JS_Running: m_nid.hIcon = m_running_icon; - else if (bacstat < 0) + break; + case JS_ErrorTerminated: m_nid.hIcon = m_error_icon; + break; + default: + if (last_jobs->size() > 0) { + job = (struct s_last_job *)last_jobs->last(); + if (job->Errors) { + m_nid.hIcon = m_warn_icon; + } else { + m_nid.hIcon = m_idle_icon; + } + } else { + m_nid.hIcon = m_idle_icon; + } + break; + } m_nid.uFlags = NIF_ICON | NIF_MESSAGE; m_nid.uCallbackMessage = WM_TRAYNOTIFY; @@ -168,7 +190,7 @@ bacMenu::SendTrayMsg(DWORD msg, int bacstat) // Try to add the Bacula status to the tip string, if possible if (m_nid.uFlags & NIF_TIP) { - strncpy(m_nid.szTip, bac_status(0), (sizeof(m_nid.szTip)-1)); + bac_status(m_nid.szTip, sizeof(m_nid.szTip)); } // Send the message @@ -201,24 +223,12 @@ LRESULT CALLBACK bacMenu::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP if (bacService::RunningAsService()) { // Attempt to add the icon if it's not already there _this->AddTrayIcon(); - // Trigger a check of the current user -// PostMessage(hwnd, WM_USERCHANGED, 0, 0); } // Update the icon _this->UpdateTrayIcon(bacstat); break; -#ifdef xxx_needed - - // DEAL WITH NOTIFICATIONS FROM THE SERVER: - case WM_SRV_CLIENT_AUTHENTICATED: - case WM_SRV_CLIENT_DISCONNECT: - // Adjust the icon accordingly - _this->UpdateTrayIcon(bacstat); - return 0; -#endif - // STANDARD MESSAGE HANDLING case WM_CREATE: return 0; @@ -311,61 +321,32 @@ LRESULT CALLBACK bacMenu::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP return 0; case WM_QUERYENDSESSION: - // Are we running as a system service? - // Or is the system shutting down (in which case we should check anyway!) - if ((!bacService::RunningAsService()) || (lParam == 0)) { - // No, so we are about to be killed + // Are we running as a system service? + // Or is the system shutting down (in which case we should check anyway!) + if ((!bacService::RunningAsService()) || (lParam == 0)) { + // No, so we are about to be killed - // If there are remote connections then we should verify - // that the user is happy about killing them. + // If there are remote connections then we should verify + // that the user is happy about killing them. - // Finally, post a quit message, just in case - PostQuitMessage(0); - return TRUE; - } - - // Tell the OS that we've handled it anyway -// PostQuitMessage(0); - return TRUE; + // Finally, post a quit message, just in case + PostQuitMessage(0); + return TRUE; + } + return TRUE; default: - if (iMsg == MENU_ABOUTBOX_SHOW) { - // External request to show our About dialog - PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0); - return 0; - } - if (iMsg == MENU_STATUS_SHOW) { - // External request to show our status - PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_STATUS, 0), 0); - return 0; - } - -#ifdef xxx_needed - if (iMsg == MENU_EVENTS_SHOW) { - // External request to show our Events dialogue - PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_EVENTS, 0), 0); - return 0; - } - - if (iMsg == MENU_SERVICEHELPER_MSG) { - // External ServiceHelper message. - // This message holds a process id which we can use to - // impersonate a specific user. In doing so, we can load their - // preferences correctly - bacService::ProcessUserHelperMessage(wParam, lParam); - - // - Trigger a check of the current user - PostMessage(hwnd, WM_USERCHANGED, 0, 0); - return 0; - } - if (iMsg == MENU_ADD_CLIENT_MSG) { - // Add Client message. This message includes an IP address - // of a listening client, to which we should connect. - - return 0; - } -#endif + if (iMsg == MENU_ABOUTBOX_SHOW) { + // External request to show our About dialog + PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0); + return 0; + } + if (iMsg == MENU_STATUS_SHOW) { + // External request to show our status + PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_STATUS, 0), 0); + return 0; + } } // Message not recognised diff --git a/bacula/src/filed/win32/wintray.h b/bacula/src/filed/win32/wintray.h index 0b210282af..54f418355b 100755 --- a/bacula/src/filed/win32/wintray.h +++ b/bacula/src/filed/win32/wintray.h @@ -72,21 +72,22 @@ protected: protected: // About dialog for this server - bacAbout m_about; + bacAbout m_about; // Status dialog for this server - bacStatus m_status; + bacStatus m_status; - bacEvents m_events; + bacEvents m_events; - HWND m_hwnd; - HMENU m_hmenu; - NOTIFYICONDATA m_nid; + HWND m_hwnd; + HMENU m_hmenu; + NOTIFYICONDATA m_nid; // The icon handles - HICON m_idle_icon; - HICON m_running_icon; - HICON m_error_icon; + HICON m_idle_icon; + HICON m_running_icon; + HICON m_error_icon; + HICON m_warn_icon; }; diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 1c9471e9aa..dbb707663d 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -261,7 +261,7 @@ struct JCR { */ struct s_last_job { dlink link; - int xNumJobs; /* no longer used */ + int Errors; /* FD/SD errors */ int JobType; int JobStatus; int JobLevel; diff --git a/bacula/src/lib/bnet_server.c b/bacula/src/lib/bnet_server.c index 74903b83fc..f4cc057527 100644 --- a/bacula/src/lib/bnet_server.c +++ b/bacula/src/lib/bnet_server.c @@ -134,7 +134,7 @@ bnet_thread_server(char *bind_addr, int port, int max_clients, workq_t *client_w for (;!quit;) { fd_set sockset; FD_ZERO(&sockset); - FD_SET(sockfd, &sockset); + FD_SET((unsigned)sockfd, &sockset); errno = 0; if ((stat = select(sockfd+1, &sockset, NULL, NULL, NULL)) < 0) { if (errno == EINTR || errno == EAGAIN) { @@ -281,7 +281,7 @@ bnet_accept(BSOCK *bsock, char *who) * Wait for a connection from the client process. */ FD_ZERO(&sockset); - FD_SET(bsock->fd, &sockset); + FD_SET((unsigned)bsock->fd, &sockset); for (;;) { /* diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index eebb5244de..6fb681a661 100755 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -263,6 +263,7 @@ static void free_common_jcr(JCR *jcr) case JT_RESTORE: case JT_ADMIN: num_jobs_run++; + last_job.Errors = jcr->Errors; last_job.JobType = jcr->JobType; last_job.JobId = jcr->JobId; last_job.VolSessionId = jcr->VolSessionId; diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index b0f604c1dc..2cf95e805f 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -35,7 +35,7 @@ extern int debug_level; /* First and last resource ids */ int r_first = R_FIRST; int r_last = R_LAST; -static RES *sres_head[R_LAST - R_FIRST]; +static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; -- 2.39.5