snaplock: main.cpp Source File

snaplock  1.7.14
The multi-computer lock service.
main.cpp
Go to the documentation of this file.
1 /*
2  * Text:
3  * snaplock/src/main.cpp
4  *
5  * Description:
6  * A daemon to synchronize processes between any number of computers
7  * by blocking all of them but one.
8  *
9  * This contains the main() function.
10  *
11  * License:
12  * Copyright (c) 2016-2019 Made to Order Software Corp. All Rights Reserved
13  *
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining a
18  * copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be included
26  * in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
29  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
32  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
34  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  */
36 
37 // ourselves
38 //
39 #include "snaplock.h"
40 
41 // our lib
42 //
43 #include <snapwebsites/log.h>
44 
45 // advgetopt lib
46 //
47 #include <advgetopt/exception.h>
48 
49 
59 bool g_isatty = false;
60 
61 
62 int main(int argc, char * argv[])
63 {
64  g_isatty = isatty(STDERR_FILENO);
65 
66  try
67  {
68  // create an instance of the snap_firewall object
69  //
70  snaplock::snaplock::pointer_t lock(std::make_shared<snaplock::snaplock>(argc, argv));
71 
72  // Now run!
73  //
74  lock->run();
75 
76  // exit normally (i.e. we received a STOP message on our
77  // connection with the Snap! Communicator service.)
78  //
79  return 0;
80  }
81  catch( advgetopt::getopt_exception_exit const & except )
82  {
83  return except.code();
84  }
85  catch(snap::snap_exception const & e)
86  {
87  SNAP_LOG_FATAL("snaplock: snap_exception caught! ")(e.what());
88  if(g_isatty)
89  {
90  std::cerr << "snaplock: snap_exception caught! " << e.what() << std::endl;
91  }
92  }
93  catch(std::invalid_argument const & e)
94  {
95  SNAP_LOG_FATAL("snaplock: invalid argument: ")(e.what());
96  if(g_isatty)
97  {
98  std::cerr << "snaplock: invalid argument: " << e.what() << std::endl;
99  }
100  }
101  catch(std::overflow_error const & e)
102  {
103  SNAP_LOG_FATAL("snaplock: std::overflow_error caught! ")(e.what());
104  if(g_isatty)
105  {
106  std::cerr << "snaplock: std::overflow_error caught! " << e.what() << std::endl;
107  }
108  }
109  catch(std::exception const & e)
110  {
111  SNAP_LOG_FATAL("snaplock: std::exception caught! ")(e.what());
112  if(g_isatty)
113  {
114  std::cerr << "snaplock: std::exception caught! " << e.what() << std::endl;
115  }
116  }
117  catch(...)
118  {
119  SNAP_LOG_FATAL("snaplock: unknown exception caught!");
120  if(g_isatty)
121  {
122  std::cerr << "snaplock: unknown exception caught! " << std::endl;
123  }
124  }
125 
126 
127  return 1;
128 }
129 
130 // vim: ts=4 sw=4 et
bool g_isatty
Define whether the standard output stream is a TTY.
Definition: main.cpp:59
std::shared_ptr< snaplock > pointer_t
Definition: snaplock.h:323
int main(int argc, char *argv[])
Definition: main.cpp:62

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly