1 /*******************************************************************************
2 
3     Test for UnixSocketExt
4 
5     Copyright:
6         Copyright (c) 2017 dunnhumby Germany GmbH.
7         All rights reserved.
8 
9     License:
10         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
11         Alternatively, this file may be distributed under the terms of the Tango
12         3-Clause BSD License (see LICENSE_BSD.txt for details).
13 
14 *******************************************************************************/
15 
16 module integrationtest.unixsockext.main;
17 
18 import ocean.transition;
19 
20 import core.sys.posix.sys.stat;
21 import ocean.core.Test;
22 import ocean.sys.ErrnoException;
23 import ocean.util.app.DaemonApp;
24 import ocean.task.Scheduler;
25 import ocean.task.Task;
26 
27 class UnixSockListeningApp : DaemonApp
28 {
29     this ( )
30     {
31         initScheduler(SchedulerConfiguration.init);
32         theScheduler.exception_handler = (Task t, Exception e) {
33             throw e;
34         };
35 
36         istring name = "Application";
37         istring desc = "Testing unix socket listener mode.";
38 
39         DaemonApp.OptionalSettings settings;
40 
41         super(name, desc, VersionInfo.init, settings);
42     }
43 
44     // Called after arguments and config file parsing.
45     override protected int run ( Arguments args, ConfigParser config )
46     {
47         this.startEventHandling(theScheduler.epoll);
48         auto errnoexception = new ErrnoException;
49 
50         // Let's check the mode of the socket!
51         stat_t stats;
52         errnoexception.enforceRetCode!(stat)().call("unix.socket", &stats);
53         test!("==")((stats.st_mode & ~S_IFMT), Octal!("0600"));
54 
55         return 0; // return code to OS
56     }
57 
58 }
59 
60 import ocean.io.device.File;
61 import ocean.util.test.DirectorySandbox;
62 
63 version (unittest) {} else
64 void main(istring[] args)
65 {
66     auto sandbox = DirectorySandbox.create(["etc", "log"]);
67 
68     File.set("etc/config.ini", "[LOG.Root]\n" ~
69                "console = false\n\n" ~
70                "[UNIX_SOCKET]\npath=unix.socket\nmode=0600");
71 
72     auto app = new UnixSockListeningApp;
73     auto ret = app.main(args);
74 }