Added XDG_RUNTIME_DIR variable support. Fixed typo in README.

This commit is contained in:
Elijah 2022-08-12 10:22:24 +00:00
parent 636fef0bda
commit e41236883e
3 changed files with 47 additions and 9 deletions

View File

@ -17,9 +17,25 @@ song_2.mp3
## Usage
First of all, you need to create named pipe (FIFO). It can be done by running following command:
First, you need to check your XDG_RUNTIME_DIR variable
```
mkfifo ~/.cache/.pipeplayer
echo $XDG_RUNTIME_DIR
```
If you see no output, then you need to export variable:
On bash, zsh etc.:
```
export XDG_RUNTIME_DIR="$HOME/.local/runtime"
```
On fish:
```
set -x XDG_RUNTIME_DIR "$HOME/.local/runtime"
```
Then make sure directory $XDG_RUNTIME_DIR exists:
```
mkdir -p "$XDG_RUNTIME_DIR"
```
Then, you can start daemon either during start of your desktop environment or window manager or even in tty with this command:

View File

@ -3,7 +3,7 @@ PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
# Name of program
VERSION = 1.0.0
VERSION = 1.1.0
NAME = pipeplayer
# Compiler

View File

@ -1,7 +1,11 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "player.h"
#include "playlist.h"
@ -20,13 +24,31 @@ int
main(int argc, char *argv[])
{
// Usage information
if (argc != 2) {
printf("Usage: %s [FIFO]\n", argv[0]);
return 1;
char *pipe, *xdg_runtime_dir;
switch (argc) {
// Path is provided
case 2:
pipe = argv[1];
break;
// If no arguments provided, pipe = $XDG_RUNTIME_DIR/pipeplayer
case 1:
if ((xdg_runtime_dir = getenv("XDG_RUNTIME_DIR")) != NULL) {
pipe = strcat(xdg_runtime_dir, "/pipeplayer");
break;
}
puts("XDG_RUNTIME_DIR variable must be set or path to fifo must be specified");
// The go to default case
default:
printf("Usage: %s - creates FIFO on $XDG_RUNTIME_DIR/pipeplayer", argv[0]);
printf(" %s [path] - creates FIFO on given path\n", argv[0]);
return 1;
}
if (access(argv[1], F_OK) != 0) {
printf("Cannot access file %s\n", argv[1]);
if (access(pipe, F_OK) != 0 && mkfifo(pipe, 0644) != 0) {
printf("Cannot create fifo at %s\n", pipe);
return 1;
}
@ -50,7 +72,7 @@ main(int argc, char *argv[])
init_player(player_ptr);
// Create and join input thread
run_threads(player_ptr, playlist_ptr, argv[1]);
run_threads(player_ptr, playlist_ptr, pipe);
// Clear player and playlist
free_player(player_ptr);