Overpass API regression suite coverage (Nova Scotia) / template_db/types.cc

template_db/types.cc

8 of 89 instrumented lines run by the suite (9.0%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#include <sys/socket.h>
20#include <sys/un.h>
21#include "types.h"
23#include <cstring>
26void copy_file(const std::string& source, const std::string& dest)
270{
280 if (!file_exists(source))
290 return;
300 if (file_exists(dest))
310 {
320 if (remove(dest.c_str()))
330 throw File_Error(errno, dest, "copy_file:1");
340 }
360 Raw_File source_file(source, O_RDONLY, S_666, "Dispatcher:1");
370 uint64 size = source_file.size("Dispatcher:2");
380 Raw_File dest_file(dest, O_RDWR|O_CREAT, S_666, "Dispatcher:3");
390 dest_file.resize(size, "Dispatcher:4");
410 Void_Pointer< uint8 > buf(64*1024);
420 while (size > 0)
430 {
440 size = read(source_file.fd(), buf.ptr, 64*1024);
450 dest_file.write(buf.ptr, size, "Dispatcher:5");
460 }
470}
50void force_link_file(const std::string& source, const std::string& dest)
510{
520 if (!file_exists(source))
530 return;
540 if (file_exists(dest))
550 {
560 if (remove(dest.c_str()))
570 throw File_Error(errno, dest, "force_link_file:1");
580 }
600 if (link(source.c_str(), dest.c_str()))
610 throw File_Error(errno, source, "force_link_file:2");
620}
65int& global_read_counter()
66462525590 q{
67462525590 q static int counter = 0;
68462525590 q return counter;
69462525590 q}
72Signal_Status& sigterm_status()
73491197590 q{
74491197590 q static Signal_Status status = Signal_Status::absent;
75491197590 q return status;
76491197590 q}
79void sigterm(int)
800{
810 sigterm_status() = Signal_Status::received;
820}
85void millisleep(uint32 milliseconds)
860{
870 struct timeval timeout_;
880 timeout_.tv_sec = milliseconds/1000;
890 timeout_.tv_usec = milliseconds*1000;
900 select(FD_SETSIZE, NULL, NULL, NULL, &timeout_);
910}
94Unix_Socket::Unix_Socket(const std::string& socket_name, uint max_num_reading_processes_)
950 : socket_descriptor(-1), max_num_reading_processes(max_num_reading_processes_)
960{
970 if (socket_name != "")
980 open(socket_name);
990}
102void Unix_Socket::open(const std::string& socket_name)
1030{
1040 socket_descriptor = socket(AF_UNIX, SOCK_STREAM, 0);
1050 if (socket_descriptor == -1)
1060 throw File_Error
1070 (errno, socket_name, "Unix_Socket::1");
1090 if (max_num_reading_processes > 0)
1100 {
1110 if (fcntl(socket_descriptor, F_SETFL, O_RDWR|O_NONBLOCK) == -1)
1120 throw File_Error
1130 (errno, socket_name, "Unix_Socket::2");
1140 }
1160 struct sockaddr_un local;
1170 local.sun_family = AF_UNIX;
1180 if (socket_name.size() < sizeof local.sun_path - 1)
1190 strcpy(local.sun_path, socket_name.c_str());
1200 else
1210 throw File_Error(0, socket_name, "Unix_Socket::3");
122#ifdef __APPLE__
123 local.sun_len = socket_name.size(); //experimental change. Not testing on MacOS known.
124#endif
1260 if (max_num_reading_processes > 0)
1270 {
1280 if (bind(socket_descriptor, (struct sockaddr*)&local,
1290 sizeof(struct sockaddr_un)) == -1)
1300 throw File_Error(errno, socket_name, "Unix_Socket::4");
1310 if (chmod(socket_name.c_str(), S_666) == -1)
1320 ; // Ignore error. If clients fail on permission problems then this cause is easy enough to find - throw File_Error(errno, socket_name, "Unix_Socket::5");
1330 if (listen(socket_descriptor, max_num_reading_processes) == -1)
1340 throw File_Error(errno, socket_name, "Unix_Socket::6");
1350 }
1360 else
1370 if (connect(socket_descriptor, (struct sockaddr*)&local,
1380 sizeof(struct sockaddr_un)) == -1)
1390 throw File_Error
1400 (errno, socket_name, "Unix_Socket::7");
1410}
144Unix_Socket::~Unix_Socket()
1450{
1460 if (socket_descriptor != -1)
1470 close(socket_descriptor);
1480}