-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support socket communication with client and systemd integration
- Loading branch information
Sian Cao
committed
May 9, 2014
1 parent
ed852ed
commit eb77c20
Showing
8 changed files
with
224 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <sys/un.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#include <iostream> | ||
#include <unordered_map> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
|
||
static int id; | ||
|
||
int dispatch(std::string cmd) { | ||
std::unordered_map<string, string> tb { | ||
{"quit", "Q"}, | ||
{"pause", "P"}, | ||
{"resume", "R"}, | ||
}; | ||
|
||
if (tb.find(cmd) == tb.end()) return -1; | ||
|
||
if (write(id, tb[cmd].c_str(), tb[cmd].size()) < 0) { | ||
perror("write"); | ||
return -1; | ||
} | ||
std::cerr << "write " << tb[cmd].size() << " bytes" << std::endl; | ||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
const char *sock_path = ":prometheus.sock"; | ||
|
||
if (argc < 2) { | ||
std::cerr << "no command specified" << std::endl; | ||
return 0; | ||
} | ||
|
||
id = socket(AF_UNIX, SOCK_STREAM, 0); | ||
if (id < 0) { | ||
perror("socket"); | ||
return -1; | ||
} | ||
|
||
struct sockaddr_un un2; | ||
memset(&un2, 0, sizeof un2); | ||
un2.sun_family = AF_UNIX; | ||
strncpy(&un2.sun_path[1], sock_path, strlen(sock_path)); | ||
if (connect(id, (struct sockaddr*)&un2, sizeof un2) < 0) { | ||
perror("connect"); | ||
close(id); | ||
return -1; | ||
} | ||
|
||
dispatch(argv[1]); | ||
close(id); | ||
|
||
ofstream ofs{"/tmp/prometheus.done"}; | ||
ofs << ""; | ||
|
||
// bad way to wait for server to finish | ||
sleep(1); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/ash | ||
|
||
run_hook() { | ||
prometheus -m text | ||
prometheusd -m text | ||
} | ||
|
||
# vim: set ft=sh: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Light Display Manager | ||
Conflicts[email protected] prometheus-quit.service | ||
After=systemd-user-sessions.service [email protected] prometheus-quit.service | ||
|
||
[Service] | ||
ExecStart=/usr/bin/lightdm | ||
Restart=always | ||
IgnoreSIGPIPE=no | ||
BusName=org.freedesktop.DisplayManager | ||
|
||
[Install] | ||
Alias=display-manager.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=Terminate Prometheus Boot Screen | ||
After=rc-local.service systemd-user-sessions.service | ||
[email protected] | ||
|
||
[Service] | ||
ExecStart=-@CMAKE_INSTALL_PREFIX@/sbin/prometheus quit | ||
Type=oneshot | ||
TimeoutSec=20 |