/* WARNING: This file was generated by dkct. Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: lprngcl.ctr */ /* Copyright (C) 2016-2017, Dirk Krause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above opyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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. */ #line 10 "lprngcl.ctr" /** @file lprngcl.c Lprng Cleanup. */ #include "dk4conf.h" #if DK4_HAVE_SYS_TYPES_H #ifndef SYS_TYPES_H_INCLUDED #include #define SYS_TYPES_H_INCLUDED 1 #endif #endif #if DK4_HAVE_UNISTD_H #ifndef UNISTD_H_INCLUDED #include #define UNISTD_H_INCLUDED 1 #endif #endif #if DK4_HAVE_PROCESS_H #ifndef PROCESS_H_INCLUDED #include #define PROCESS_H_INCLUDED 1 #endif #endif #if DK4_HAVE_IO_H #ifndef IO_H_INCLUDED #include #define IO_H_INCLUDED 1 #endif #endif #if DK4_HAVE_FCNTL_H #ifndef FCNTL_H_INCLUDED #include #define FCNTL_H_INCLUDED 1 #endif #endif #if DK4_HAVE_SIGNAL_H #ifndef SIGNAL_H_INCLUDED #include #define SIGNAL_H_INCLUDED 1 #endif #endif #if DK4_HAVE_MATH_H #ifndef MATH_H_INCLUDED #include #define MATH_H_INCLUDED 1 #endif #endif #include "dk4types.h" #include "dk4const.h" #include "dk4vers.h" #include "dk4str8.h" #include "dk4strd.h" #include "dk4app.h" #include "dk4aopt.h" #include "dk4enc.h" #include "dk4fput.h" #include "dk4mem.h" #include "dk4mema.h" #include "dk4fput.h" #include "dk4tspdk.h" #include "dk4sock.h" #include "dk4socka.h" #include "dk4user.h" #include "dk4rec.h" #line 86 "lprngcl.ctr" /** Buffer for request and response data. */ static char buf[4096]; /** Current queue complete name. */ static dkChar curqueue[1024]; /** Current user name. */ static dkChar username[1024]; /** Queue name in 8 bit characters. */ static char queue8[1024]; /** User name in 8 bit characters. */ static char user8[1024]; /** Default help text, used if help text file is not found. */ static const dkChar * const lprngcl_help_text[] = { dkT(""), dkT("Clean up LPRng queues"), dkT(""), dkT("lprngcl [-t seconds] [-a] ..."), dkT("lprngcl [--help] [--version] [--license] [--manual]"), dkT(""), dkT("Specify queues in name@host notation."), dkT(""), dkT("-t seconds\t--timeout=seconds\tTimeout for network operations."), dkT("-a\t\t--ascii\t\t\tServer uses ASCII, not UTF-8."), dkT(""), dkT("\t\t--help\t\t\tShow this short help text."), dkT("\t\t--version\t\tShow version information."), dkT("\t\t--license\t\tShow license information."), dkT("\t\t--manual\t\t*** SHOW FULL MANUAL ***"), dkT(""), NULL #line 134 "lprngcl.ctr" }; /** License conditions. */ static const dkChar * const lprngcl_license_text[] = { dkT("This software uses code from the following projects, either directly or as"), dkT("a library:"), dkT(""), dkT("dktools\t\tDirk Krause's tools and libraries."), dkT("\t\tSee http://dktools.sourceforge.net/ for more information."), #if DK4_HAVE_ZLIB_H dkT(""), dkT("zlib\t\tData compression library."), dkT("\t\tSee http://www.zlib.net/ for more information."), #endif #if DK4_HAVE_BZLIB_H dkT(""), dkT("bzip2\t\tData compression program and library."), dkT("\t\tSee http://www.bzip.org/ for more information."), #endif dkT(""), dkT("All the licenses below apply to the program."), dkT("Licenses for used libraries are shown as found on my Scientific Linux 6.x"), dkT("computer in the /usr/share/doc directory on 2015-04-01. Check the project"), dkT("homepages of the used libraries for additional information and/or updated"), dkT("license terms."), dkT(""), dkT(""), dkT("DK tools and libraries license"), dkT("=============================="), dkT("Copyright (c) 2015-2016, Dirk Krause"), dkT("All rights reserved."), dkT(""), dkT("Redistribution and use in source and binary forms, with or without"), dkT("modification, are permitted provided that the following conditions are met:"), dkT(""), dkT("* Redistributions of source code must retain the above copyright notice,"), dkT(" this list of conditions and the following disclaimer."), dkT("* Redistributions in binary form must reproduce the above copyright"), dkT(" notice, this list of conditions and the following disclaimer in the"), dkT(" documentation and/or other materials provided with the distribution."), dkT("* Neither the name of the Dirk Krause nor the names of contributors may be"), dkT(" used to endorse or promote products derived from this software without"), dkT(" specific prior written permission."), dkT(""), dkT("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\""), dkT("AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE"), dkT("IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE"), dkT("ARE DISCLAIMED."), dkT(""), dkT("IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,"), dkT("INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,"), dkT("BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,"), dkT("DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY"), dkT("OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING"), dkT("NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,"), dkT("EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."), #if DK4_HAVE_ZLIB_H dkT(""), dkT(""), dkT("Zlib license"), dkT("============"), dkT("(C) 1995-2004 Jean-loup Gailly and Mark Adler"), dkT(""), dkT("This software is provided 'as-is', without any express or implied"), dkT("warranty. In no event will the authors be held liable for any damages"), dkT("arising from the use of this software."), dkT(""), dkT("Permission is granted to anyone to use this software for any purpose,"), dkT("including commercial applications, and to alter it and redistribute it"), dkT("freely, subject to the following restrictions:"), dkT(""), dkT("1. The origin of this software must not be misrepresented; you must not"), dkT(" claim that you wrote the original software. If you use this software"), dkT(" in a product, an acknowledgment in the product documentation would be"), dkT(" appreciated but is not required."), dkT("2. Altered source versions must be plainly marked as such, and must not be"), dkT(" misrepresented as being the original software."), dkT("3. This notice may not be removed or altered from any source distribution."), dkT(""), dkT("Jean-loup Gailly Mark Adler"), dkT("jloup@gzip.org madler@alumni.caltech.edu"), #endif #if DK4_HAVE_BZLIB_H dkT(""), dkT(""), dkT("Bzip2 and libbzip2 library license"), dkT("=================================="), dkT("This program, \"bzip2\", the associated library \"libbzip2\", and all"), dkT("documentation, are copyright (C) 1996-2007 Julian R Seward. All"), dkT("rights reserved."), dkT(""), dkT("Redistribution and use in source and binary forms, with or without"), dkT("modification, are permitted provided that the following conditions"), dkT("are met:"), dkT(""), dkT("1. Redistributions of source code must retain the above copyright"), dkT(" notice, this list of conditions and the following disclaimer."), dkT(""), dkT("2. The origin of this software must not be misrepresented; you must "), dkT(" not claim that you wrote the original software. If you use this "), dkT(" software in a product, an acknowledgment in the product "), dkT(" documentation would be appreciated but is not required."), dkT(""), dkT("3. Altered source versions must be plainly marked as such, and must"), dkT(" not be misrepresented as being the original software."), dkT(""), dkT("4. The name of the author may not be used to endorse or promote "), dkT(" products derived from this software without specific prior written "), dkT(" permission."), dkT(""), dkT("THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS"), dkT("OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED"), dkT("WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE"), dkT("ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY"), dkT("DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL"), dkT("DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE"), dkT("GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS"), dkT("INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,"), dkT("WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING"), dkT("NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS"), dkT("SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."), dkT(""), dkT("Julian Seward, jseward@bzip.org"), dkT("bzip2/libbzip2 version 1.0.5 of 10 December 2007"), #endif dkT(""), NULL #line 265 "lprngcl.ctr" }; /** Options used by the program. */ static const dk4_option_specification_t lprngcl_options[] = { /* Timeout for connection attempts and other network operations. */ { dkT('t'), dkT("timeout"), DK4_OPT_ARG_DOUBLE }, /* Remote host uses ASCII encoding, not UTF-8. */ { dkT('a'), dkT("ascii"), DK4_OPT_ARG_NONE }, /* Verbose output. */ { dkT('v'), dkT("verbose"), DK4_OPT_ARG_NONE } }; /** Constant texts used by the program, not localized. */ static const dkChar * const lprngcl_kwnl[] = { /* 0 */ dkT("dktools"), /* 1 */ dkT("lprngcl.txt"), /* 2 */ dkT("lprngcl.str"), NULL #line 300 "lprngcl.ctr" }; /** Defaults for keywords, replaced by localized version if found. */ static const dkChar * const lprngcl_kw_def[] = { /* 0 */ dkT("Failed to set up signal handlers!"), /* 1 */ dkT("Failed to restore signal handlers!"), /* 2 */ dkT("Failed to set up text stream processor!"), /* 3 */ dkT("Failed to construct request!\nQueue or user name too long!"), /* 4 */ dkT("Failed to convert queue name to 8 bit text!"), /* 5 */ dkT("No host name specified in queue!"), /* 6 */ dkT("Queue name too long!"), /* 7 */ dkT("Failed to obtain command line argument (bug)!"), /* 8 */ dkT("Failed to convert user name to 8 bit text!"), /* 9 */ dkT("Failed to find current user name!"), /* 10 */ dkT("Queue name(s) required!"), /* 11 */ dkT("Failed to write to standard output!"), /* 12 */ dkT("Request:\n\""), /* 13 */ dkT("\"."), NULL #line 362 "lprngcl.ctr" }; static const char * const lprngcl_c8_kw[] = { /* 0 */ " ", /* 1 */ "\n", /* 2 */ "all", NULL #line 381 "lprngcl.ctr" }; /** Application object. */ static dk4_app_t *app = NULL; /** Message texts, changed to localized texts if possible. */ static const dkChar * const *msg = lprngcl_kw_def; /** Size of lprngcl_options array. */ static const size_t lprngcl_sz_options = sizeof(lprngcl_options)/sizeof(dk4_option_specification_t); /** Size of lprngcl_kw_def array. */ static size_t sz_msg = (sizeof(lprngcl_kw_def)/sizeof(DK4_PDKCHAR) - 1); /** Size of buffer for current queue. */ static const size_t szcurqueue = DK4_SIZEOF(curqueue,dkChar); /** Size of buffer. */ static size_t szbuf = sizeof(buf); /** Timeout (seconds) for network operations. */ static long to_secs = 0L; /** Timeout (microseconds) for network operations. */ static long to_usecs = 0L; /** Exit status code. */ static int exval = EXIT_FAILURE; /** Flag: Errors while writing to stdout. */ static int wrerror = 0; /** Flag: Remote host uses UTF-8 encoding. */ static int isUtf8 = 1; /** Flag: Produce verbose output. */ static int isVerbose = 0; #ifdef SIGPIPE /** Indicator: SIGPIPE signal received. */ static DK4_VOLATILE dk4_sig_atomic_t sig_had_pipe = 0; #endif /** Indicator: SIGINT signal received. */ static DK4_VOLATILE dk4_sig_atomic_t sig_had_int = 0; /** Indicator: SIGTERM signal received. */ static DK4_VOLATILE dk4_sig_atomic_t sig_had_term = 0; static DK4_VOLATILE dk4_sig_atomic_t * sig_pass_pointer(DK4_VOLATILE dk4_sig_atomic_t *ptr) { return ptr; } #ifdef SIGPIPE /** Handler for SIGPIPE signal. @param signo Signal number (always SIGPIPE, ignored). */ static void sig_handler_pipe(int signo) { *sig_pass_pointer(&sig_had_pipe) = 1; } #endif /** Handler for SIGINT signal. @param signo Signal number (always SIGINT, ignored). */ static void sig_handler_int(int signo) { *sig_pass_pointer(&sig_had_int) = 1; } /** Handler for SIGTERM signal. @param signo Signal number (always SIGTERM, ignored). */ static void sig_handler_term(int signo) { *sig_pass_pointer(&sig_had_term) = 1; } /** Read value from volatile atomic type. This function is necessary as some compilers mis-optimize direct access to volatile variables (at least if you believe one of the coding standards). @param ap Pointer to volatile atomic variable. @return Contents of the variable. */ static dk4_sig_atomic_t sig_read_atomic(DK4_VOLATILE dk4_sig_atomic_t *ap) { return (*ap); } /** Check whether we can continue or if a signal was received. @param check_pipe Flag: Check for occured SIGPIPE signal too. @return 1 if the program can continue, 0 if a signal was received. */ static int sig_can_continue(int check_pipe) { int back = 1; #ifdef SIGPIPE if (0 != check_pipe) { if (0 != sig_read_atomic(&sig_had_pipe)) { back = 0; } } #endif if (0 != sig_read_atomic(&sig_had_int )) { back = 0; } if (0 != sig_read_atomic(&sig_had_term)) { back = 0; } return back; } /** Use timeout value specified as double. @param to Timeout for network operations. */ static void use_timeout(double to) { #line 553 "lprngcl.ctr" if (0.0 > to) { to = -1.0 * to; } to_secs = (long)floor(to); to = to - floor(to); to = to * 1000000.0; to_usecs = (long)floor(to); #line 559 "lprngcl.ctr" } /** Process command line options. @return 1 on success, 0 on error. */ static int process_options(void) { double to = 0.0; int back = 1; #line 573 "lprngcl.ctr" if (0 != dk4app_opt_is_set_short(app, dkT('t'), NULL)) { if (0 != dk4app_opt_get_double_short(&to, app, dkT('t'), NULL)) { #line 576 "lprngcl.ctr" use_timeout(to); } } else { } if (0 != dk4app_opt_is_set_short(app, dkT('a'), NULL)) { #line 582 "lprngcl.ctr" isUtf8 = 0; } if (0 != dk4app_opt_is_set_short(app, dkT('v'), NULL)) { #line 586 "lprngcl.ctr" isVerbose = 1; } #line 589 "lprngcl.ctr" return back; } /** Character handler for text stream processing. */ static int lprngcl_char_handler( void *obj, dkChar c, dk4_text_stream_position_t *pos, dk4_er_t *erp ) { int back = DK4_TSP_RES_OK; if (0 == dk4fputc(c, stdout, NULL)) { exval = EXIT_FAILURE; wrerror = 1; } return back; } /** Process one request to delete print jobs. @param hptr Host name pointer. @param fullqueue Full queue name. */ static void process_one_delete_request(const dkChar *hptr, const dkChar *fullqueue) { dk4_tspdk_t tspdk; size_t rql; size_t wrb; int cc; int tspok; int res; dk4_socket_t sock; #line 631 "lprngcl.ctr" rql = dk4str8_len(buf); sock = dk4socket_tcp_client_for_host_port_app( hptr, 515, 0, to_secs, to_usecs, app ); if (INVALID_SOCKET != sock) { #line 636 "lprngcl.ctr" wrb = rql; if (0 != isVerbose) { #line 638 "lprngcl.ctr" if (0 == dk4fputs(fullqueue, stdout, NULL)) { wrerror = 1; #line 640 "lprngcl.ctr" exval = EXIT_FAILURE; } if (0 == dk4fputc(dkT('\n'), stdout, NULL)) { wrerror = 1; #line 644 "lprngcl.ctr" exval = EXIT_FAILURE; } } #line 647 "lprngcl.ctr" res = dk4socket_send_attempt_app( sock, buf, &wrb, 0, to_secs, to_usecs, app, 1 ); #line 650 "lprngcl.ctr" switch (res) { case DK4_SOCKET_RESULT_SUCCESS : case DK4_SOCKET_RESULT_IN_PROGRESS : { #line 654 "lprngcl.ctr" if ((0 != isVerbose) && (DK4_SOCKET_RESULT_SUCCESS == res)) { #line 656 "lprngcl.ctr" res = dk4socket_shutdown_app(sock, DK4_SOCKET_SHUT_WRITE, app); if (DK4_SOCKET_RESULT_SUCCESS == res) { #line 658 "lprngcl.ctr" tspok = dk4tspdk_setup_char( &tspdk, NULL, lprngcl_char_handler, dk4app_get_stdout_encoding(app), ( (0 != isUtf8) ? (DK4_FILE_ENCODING_UTF8) : (DK4_FILE_ENCODING_ASCII) ), NULL ); if (0 == tspok) { #line 669 "lprngcl.ctr" /* ERROR: Failed to set up text stream processor */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 2); exval = EXIT_FAILURE; } cc = 1; do { if (0 != sig_can_continue(0)) { #line 676 "lprngcl.ctr" wrb = sizeof(buf); res = dk4socket_recv_app( sock, buf, &wrb, 0, to_secs, to_usecs, app ); if (DK4_SOCKET_RESULT_SUCCESS == res) { #line 681 "lprngcl.ctr" if (0 == wrb) { #line 682 "lprngcl.ctr" cc = 0; } else { #line 684 "lprngcl.ctr" if (0 != tspok) { #line 685 "lprngcl.ctr" res = dk4tspdk_add_bytes(&tspdk,(unsigned char *)buf,wrb); if (DK4_TSP_RES_OK != res) { #line 687 "lprngcl.ctr" exval = EXIT_FAILURE; tspok = 0; } } } } else { #line 693 "lprngcl.ctr" cc = 0; } } else { #line 696 "lprngcl.ctr" cc = -1; } } while(1 == cc); if ((0 == cc) && (0 != tspok)) { #line 700 "lprngcl.ctr" res = dk4tspdk_finish(&tspdk); if (DK4_TSP_RES_OK != res) { #line 702 "lprngcl.ctr" exval = EXIT_FAILURE; } } } else { #line 706 "lprngcl.ctr" exval = EXIT_FAILURE; } } else { #line 709 "lprngcl.ctr" res = dk4socket_shutdown_app(sock, DK4_SOCKET_SHUT_WRITE, app); if (DK4_SOCKET_RESULT_SUCCESS == res) { #line 711 "lprngcl.ctr" cc = 1; do { if (0 != sig_can_continue(0)) { #line 714 "lprngcl.ctr" wrb = sizeof(buf); res = dk4socket_recv_app( sock, buf, &wrb, 0, to_secs, to_usecs, app ); if (DK4_SOCKET_RESULT_SUCCESS == res) { #line 719 "lprngcl.ctr" if (0 == wrb) { #line 720 "lprngcl.ctr" cc = 0; } } else { #line 723 "lprngcl.ctr" cc = 0; } } else { #line 726 "lprngcl.ctr" cc = -1; } } while(1 == cc); } else { #line 730 "lprngcl.ctr" exval = EXIT_FAILURE; } } } break; #if TRACE_DEBUG default : { #line 736 "lprngcl.ctr" } break; #endif } res = dk4socket_close_app(sock, app); if (DK4_SOCKET_RESULT_SUCCESS != res) { #line 741 "lprngcl.ctr" exval = EXIT_FAILURE; } } else { #line 744 "lprngcl.ctr" exval = EXIT_FAILURE; } #line 747 "lprngcl.ctr" } /** Send requests to delete the users print jobs. @param xargc Number of queue names. */ static void send_delete_requests(int xargc) { const dkChar *xargv = NULL; /* Current cmd line argument */ dkChar *hptr = NULL; /* Start of host name */ int res = 0; /* Text conversion result */ int i = 0; /* Current cmd line arg index */ #line 763 "lprngcl.ctr" if (0 != dk4user_get_logname(username, DK4_SIZEOF(username,dkChar),0, NULL)) { #line 765 "lprngcl.ctr" if (0 != isUtf8) { #line 766 "lprngcl.ctr" res = dk4recode_dk_to_any( user8, sizeof(user8), DK4_ENCODING_UTF8, username, dk4app_get_encoding(app), NULL ); } else { #line 771 "lprngcl.ctr" res = dk4recode_dk_to_any( user8, sizeof(user8), DK4_ENCODING_ASCII, username, dk4app_get_encoding(app), NULL ); } if (0 != res) { #line 777 "lprngcl.ctr" exval = EXIT_SUCCESS; for (i = 0; ((i < xargc) && (sig_can_continue(0))); i++) { #line 780 "lprngcl.ctr" xargv = dk4app_get_argv(app, i); if (NULL != xargv) { #line 782 "lprngcl.ctr" if (0 != dk4str_cpy_s(curqueue, szcurqueue, xargv, NULL)) { #line 784 "lprngcl.ctr" hptr = dk4str_chr(curqueue, dkT('@')); if (NULL != hptr) { *(hptr++) = dkT('\0'); hptr = dk4str_start(hptr, NULL); if (NULL != hptr) { #line 789 "lprngcl.ctr" if (0 != isUtf8) { #line 790 "lprngcl.ctr" res = dk4recode_dk_to_any( queue8, sizeof(queue8), DK4_ENCODING_UTF8, curqueue, dk4app_get_encoding(app), NULL ); } else { #line 795 "lprngcl.ctr" res = dk4recode_dk_to_any( queue8, sizeof(queue8), DK4_ENCODING_ASCII, curqueue, dk4app_get_encoding(app), NULL ); } if (0 != res) { #line 801 "lprngcl.ctr" res = 1; if (0 == dk4str8_cpy_s(buf, szbuf, lprngcl_c8_kw[0], NULL)) { res = 0; #line 804 "lprngcl.ctr" buf[0] = '\0'; } if (0 == dk4str8_cat_s(buf, szbuf, queue8, NULL)) { res = 0; #line 808 "lprngcl.ctr" } if (0 == dk4str8_cat_s(buf, szbuf, lprngcl_c8_kw[0], NULL)) { res = 0; #line 811 "lprngcl.ctr" } if (0 == dk4str8_cat_s(buf, szbuf, user8, NULL)) { res = 0; #line 814 "lprngcl.ctr" } if (0 == dk4str8_cat_s(buf, szbuf, lprngcl_c8_kw[0], NULL)) { res = 0; #line 817 "lprngcl.ctr" } if (0 == dk4str8_cat_s(buf, szbuf, user8, NULL)) { res = 0; #line 820 "lprngcl.ctr" } if (0 != res) { #line 822 "lprngcl.ctr" /* LOG Print removal request */ #if DK4_CHAR_SIZE == 1 dk4app_log_3(app, msg, sz_msg, DK4_LL_INFO, 12, 13, buf); #endif } if (0 == dk4str8_cat_s(buf, szbuf, lprngcl_c8_kw[1], NULL)) { res = 0; #line 829 "lprngcl.ctr" } buf[0] = 0x05; if (0 != res) { #line 832 "lprngcl.ctr" process_one_delete_request(hptr, xargv); } else { #line 834 "lprngcl.ctr" /* ERROR: Failed to construct request */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 3); } } else { #line 838 "lprngcl.ctr" exval = EXIT_FAILURE; /* ERROR: Failed to convert queue name to 8 bit text */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 4); } } else { #line 843 "lprngcl.ctr" exval = EXIT_FAILURE; /* ERROR: No host name in queue */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 5); } } else { #line 848 "lprngcl.ctr" exval = EXIT_FAILURE; /* ERROR: No host name in queue */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 5); } } else { #line 853 "lprngcl.ctr" exval = EXIT_FAILURE; /* ERROR: Queue name too long */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 6); } } else { #line 858 "lprngcl.ctr" exval = EXIT_FAILURE; /* ERROR: Failed to obtain command line argument */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 7); } } } else { #line 864 "lprngcl.ctr" /* ERROR: Failed to recode user name to 8 bit characters */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 8); } } else { #line 868 "lprngcl.ctr" /* ERROR: Failed to find current user name */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 9); } #line 872 "lprngcl.ctr" } /** The real work. */ static void run_the_functions(void) { int xargc = 0; #line 884 "lprngcl.ctr" if (0 != process_options()) { #line 885 "lprngcl.ctr" xargc = dk4app_get_argc(app); if (0 < xargc) { #line 887 "lprngcl.ctr" if (0 != dk4socket_up_app(app)) { #line 888 "lprngcl.ctr" send_delete_requests(xargc); dk4socket_down_app(app); } else { #line 891 "lprngcl.ctr" exval = EXIT_FAILURE; } } else { #line 894 "lprngcl.ctr" /* ERROR: No queues specified */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 10); } } #if TRACE_DEBUG else { #line 900 "lprngcl.ctr" } #endif #line 903 "lprngcl.ctr" } #if DK4_HAVE_SIGACTION /** Set signal handlers and run. */ static void run_with_signals(void) { #ifdef SIGPIPE struct sigaction opipe; #endif struct sigaction oint; struct sigaction oterm; #ifdef SIGPIPE struct sigaction npipe; #endif struct sigaction nint; struct sigaction nterm; int success = 0; #line 926 "lprngcl.ctr" #ifdef SIGPIPE /* Set up signal handling for SIGPIPE. */ DK4_MEMRES(&npipe, sizeof(npipe)); npipe.sa_handler = sig_handler_pipe; npipe.sa_flags = 0; if (0 != sigemptyset(&npipe.sa_mask)) { #line 933 "lprngcl.ctr" /* ERROR: Failed to set up masked signal set for SIGPIPE */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto finished; } if (0 != sigaddset(&npipe.sa_mask, SIGPIPE)) { #line 938 "lprngcl.ctr" /* ERROR: Failed to set up masked signal set for SIGPIPE */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto finished; } if (0 != sigaction(SIGPIPE, &npipe, &opipe)) { #line 943 "lprngcl.ctr" /* ERROR: Failed to set up signal handler for SIGPIPE */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto finished; } #endif /* Set up signal handling for SIGINT. */ DK4_MEMRES(&nint, sizeof(nint)); nint.sa_handler = sig_handler_int; nint.sa_flags = 0; if (0 != sigemptyset(&nint.sa_mask)) { #line 955 "lprngcl.ctr" /* ERROR: Failed to set up masked signal set for SIGINT */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto restore_old_pipe; } if (0 != sigaddset(&nint.sa_mask, SIGINT)) { #line 960 "lprngcl.ctr" /* ERROR: Failed to set up masked signal set for SIGINT */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto restore_old_pipe; } if (0 != sigaction(SIGINT, &nint, &oint)) { #line 965 "lprngcl.ctr" /* ERROR: Failed to set up signal handler for SIGINT */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto restore_old_pipe; } /* Set up signal handling for SIGTERM */ DK4_MEMRES(&nterm, sizeof(nterm)); nterm.sa_handler = sig_handler_term; nterm.sa_flags = 0; if (0 != sigemptyset(&nterm.sa_mask)) { #line 976 "lprngcl.ctr" /* ERROR: Failed to set up masked signal set for SIGTERM */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto restore_old_int; } if (0 != sigaddset(&nterm.sa_mask, SIGTERM)) { #line 981 "lprngcl.ctr" /* ERROR: Failed to set up masked signal set for SIGTERM */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto restore_old_int; } if (0 != sigaction(SIGTERM, &nterm, &oterm)) { #line 986 "lprngcl.ctr" /* ERROR: Failed to set up signal handler for SIGTERM */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 0); goto restore_old_int; } success = 1; #line 992 "lprngcl.ctr" run_the_functions(); /* Restore signal handling for SIGTERM. */ if (0 != sigaction(SIGTERM, &oterm, NULL)) { #line 997 "lprngcl.ctr" /* ERROR: Failed to restore old SIGTERM settings */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 1); success = 0; } /* Restore signal handling for SIGINT. */ restore_old_int: if (0 != sigaction(SIGINT, &oint, NULL)) { #line 1006 "lprngcl.ctr" /* ERROR: Failed to restore old SIGPIPE settings */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 1); success = 0; } #ifdef SIGPIPE /* Restore signal handling for SIGPIPE. */ restore_old_pipe: if (0 != sigaction(SIGPIPE, &opipe, NULL)) { #line 1016 "lprngcl.ctr" /* ERROR: Failed to restore old SIGPIPE settings */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 1); success = 0; } #endif /* Set exit status code if error occured. */ finished: if (0 == success) { #line 1026 "lprngcl.ctr" exval = EXIT_FAILURE; } #line 1029 "lprngcl.ctr" } #else #if DK4_HAVE_SIGSET /** Set signal handlers and run. */ static void run_with_signals(void) { #ifdef SIGPIPE dk4_sig_handler_t *oldpipe = NULL; #endif dk4_sig_handler_t *oldint = NULL; dk4_sig_handler_t *oldterm = NULL; #line 1044 "lprngcl.ctr" #ifdef SIGPIPE oldpipe = sigset(SIGPIPE, sig_handler_pipe); #endif oldint = sigset(SIGINT, sig_handler_int); oldterm = sigset(SIGTERM, sig_handler_term); run_the_functions(); sigset(SIGTERM, oldterm); sigset(SIGINT, oldint); #ifdef SIGPIPE sigset(SIGPIPE, oldpipe); #endif #line 1056 "lprngcl.ctr" } #else #if DK4_HAVE_SIGNAL /** Set signal handlers and run. */ static void run_with_signals(void) { #ifdef SIGPIPE dk4_sig_handler_t *oldpipe = NULL; #endif dk4_sig_handler_t *oldint = NULL; dk4_sig_handler_t *oldterm = NULL; #line 1071 "lprngcl.ctr" #ifdef SIGPIPE oldpipe = signal(SIGPIPE, sig_handler_pipe); #endif oldint = signal(SIGINT, sig_handler_int); oldterm = signal(SIGTERM, sig_handler_term); run_the_functions(); signal(SIGTERM, oldterm); signal(SIGINT, oldint); #ifdef SIGPIPE signal(SIGPIPE, oldpipe); #endif #line 1083 "lprngcl.ctr" } #else /** Set signal handlers and run. */ static void run_with_signals(void) { #line 1092 "lprngcl.ctr" run_the_functions(); #line 1094 "lprngcl.ctr" } #endif #endif #endif /** Main function. @param argc Number of command line arguments. @param argv Command line arguments array. @return 0 on success, all other values indicate errors. */ #if DK4_CHAR_SIZE > 1 int wmain(int argc, wchar_t *argv[]) #else int main(int argc, char *argv[]) #endif { #line 1113 "lprngcl.ctr" #line 1114 "lprngcl.ctr" dk4fput_initialize_stdout(); dk4fput_initialize_stderr(); app = dk4app_open_cmd( argc, argv, lprngcl_options, lprngcl_sz_options, lprngcl_kwnl[0], DKT_VERSION_DK, lprngcl_kwnl[1], lprngcl_help_text, lprngcl_license_text ); if (NULL != app) { #line 1122 "lprngcl.ctr" sz_msg = dk4app_string_table_size(lprngcl_kw_def); msg = dk4app_string_table(app, lprngcl_kwnl[2], lprngcl_kw_def); if (0 != dk4app_can_run_normally(app)) { #line 1125 "lprngcl.ctr" run_with_signals(); } else { #line 1127 "lprngcl.ctr" if (0 != dk4app_help_version_license(app)) { exval = EXIT_SUCCESS; } } if (0 != wrerror) { #line 1132 "lprngcl.ctr" /* ERROR: Failed to write to standard output */ dk4app_log_1(app, msg, sz_msg, DK4_LL_ERROR, 11); } dk4app_close(app); } #if TRACE_DEBUG else { #line 1139 "lprngcl.ctr" } #endif fflush(stdout); fflush(stderr); dk4fput_cleanup_stderr(); dk4fput_cleanup_stdout(); #line 1146 "lprngcl.ctr" #line 1147 "lprngcl.ctr" exit(exval); return exval; }