namespace FreeDV {
const char * program_name = 0;
-};
+}
int
main(int argc, char * * argv)
+++ /dev/null
-#include <iostream>
-#include <unistd.h>
-#include <limits.h>
-#include <grp.h>
-
-static const char insufficient_privilege_message[] =
-"Warning: The user running the program is not a member of the "
-"\"audio\" group.\n"
-"This may make it impossible to access audio devices.\n"
-"To fix, use one of these solutions:\n"
-"\tadd the user to the \"audio\" group.\n"
-"\tadd the setgid-audio privilege to the executable file\n"
-"with these commands, as root:\n"
-"\n"
-"\t\tchgrp audio filename\n"
-"\t\tchmod 2755 filename\n"
-"\n"
-"Alternatively, you can execute this program as root.\n\n";
-
-namespace FreeDV {
- void
- check_privileges()
- {
- const int uid = getuid();
- const int euid = geteuid();
-
- if ( uid == 0 || euid == 0 )
- return;
-
- const struct group * audio = getgrnam("audio");
- const int gid = getgid();
- const int egid = getgid();
-
- if ( audio ) {
- gid_t groups[NGROUPS_MAX];
- int size = sizeof(groups) / sizeof(*groups);
- int length;
-
- if ( gid == audio->gr_gid || egid == audio->gr_gid )
- return;
-
- if ( (length = getgroups(size, groups)) > 0 ) {
- for ( int i = 0; i < length; i++ ) {
- if ( groups[i] == audio->gr_gid )
- return;
- }
- }
- std::cerr << insufficient_privilege_message << std::endl;
- }
- }
-}
+++ /dev/null
-#include "drivers.h"
-#include <string>
-#include <cstring>
-#include <iostream>
-#include <unistd.h>
-#include <errno.h>
-
-#ifdef _POSIX_PRIORITY_SCHEDULING
-#include <sched.h>
-#endif
-
-#ifdef _POSIX_MEMLOCK_RANGE
-#include <sys/mman.h>
-#endif
-
-
-
-namespace FreeDV {
- static const char privilege_message_a[] =
- "Warning: Insufficient privilege to set a real-time scheduling priority,\n"
- "or to lock memory.\n"
- "This could cause audio to be interrupted while other programs use the CPU.\n"
- "To fix: As root, run\n"
- "\n"
- "\tsetcap cap_sys_nice+ep "; /* program_name */
- static const char privilege_message_b[] = "\n\tsetcap cap_ipc_lock+ep ";
- /* program_name */
- static const char privilege_message_c[] = "\n\n"
- "That will allow you to use a real-time scheduling priority and locked\n"
- "memory while running as any user.\n"
- "Alternatively, you can execute this program as root.\n\n";
-
- static const char old_kernel_message[] =
- "This kernel doesn't seem to have real-time facilities or memory locking.\n"
- "If audio is sometimes interrupted, try a newer kernel.\n";
-
- void
- set_scheduler()
- {
- bool insufficient_privilege = false;
- bool old_kernel = false;
-
-#ifdef _POSIX_PRIORITY_SCHEDULING
- // Put this process on the round-robin realtime scheduling queue at the
- // minimum priority. Other real-time processes (perhaps portaudio) can
- // run with a higher priority than this, but this process will run at
- // a higher priority than all normal processes.
- sched_param p;
- int policy = SCHED_RR;
-
- p.sched_priority = sched_get_priority_min(policy);
- const int result = sched_setscheduler(0, policy, &p);
- if ( result < 0 ) {
- std::cerr << "sched_setscheduler: " << strerror(errno) << std::endl;
- if ( errno == EINVAL )
- old_kernel = true;
- if ( errno == EPERM )
- insufficient_privilege = true;
- }
-#endif
-
-#ifdef _POSIX_MEMLOCK_RANGE
- if ( mlockall(MCL_CURRENT|MCL_FUTURE) < 0 ) {
- std::cerr << "mlockall: " << strerror(errno) << std::endl;
- if ( errno == EINVAL )
- old_kernel = true;
- if ( errno == EPERM )
- insufficient_privilege = true;
- }
-#endif
- if ( old_kernel )
- std::cerr << old_kernel_message;
- else if ( insufficient_privilege )
- std::cerr << privilege_message_a;
- std::cerr << program_name;
- std::cerr << privilege_message_b;
- std::cerr << program_name;
- std::cerr << privilege_message_c;
- }
-}
--- /dev/null
+#include <iostream>
+#include <unistd.h>
+#include <limits.h>
+#include <grp.h>
+
+static const char insufficient_privilege_message[] =
+"Warning: The user running the program is not a member of the "
+"\"audio\" group.\n"
+"This may make it impossible to access audio devices.\n"
+"To fix, use one of these solutions:\n"
+"\tadd the user to the \"audio\" group.\n"
+"\tadd the setgid-audio privilege to the executable file\n"
+"with these commands, as root:\n"
+"\n"
+"\t\tchgrp audio filename\n"
+"\t\tchmod 2755 filename\n"
+"\n"
+"Alternatively, you can execute this program as root.\n\n";
+
+namespace FreeDV {
+ void
+ check_privileges()
+ {
+ const uid_t uid = getuid();
+ const uid_t euid = geteuid();
+
+ if ( uid == 0 || euid == 0 )
+ return;
+
+ const struct group * audio = getgrnam("audio");
+ const gid_t gid = getgid();
+ const gid_t egid = getgid();
+
+ if ( audio ) {
+ gid_t groups[NGROUPS_MAX];
+ int size = sizeof(groups) / sizeof(*groups);
+ int length;
+
+ if ( gid == audio->gr_gid || egid == audio->gr_gid )
+ return;
+
+ if ( (length = getgroups(size, groups)) > 0 ) {
+ for ( unsigned int i = 0; i < length; i++ ) {
+ if ( groups[i] == audio->gr_gid )
+ return;
+ }
+ }
+ std::cerr << insufficient_privilege_message << std::endl;
+ }
+ }
+}
--- /dev/null
+#include "drivers.h"
+#include <string>
+#include <cstring>
+#include <iostream>
+#include <unistd.h>
+#include <errno.h>
+
+#ifdef _POSIX_PRIORITY_SCHEDULING
+#include <sched.h>
+#endif
+
+#ifdef _POSIX_MEMLOCK_RANGE
+#include <sys/mman.h>
+#endif
+
+
+
+namespace FreeDV {
+ static const char privilege_message_a[] =
+ "Warning: Insufficient privilege to set a real-time scheduling priority,\n"
+ "or to lock memory.\n"
+ "This could cause audio to be interrupted while other programs use the CPU.\n"
+ "To fix: As root, run\n"
+ "\n"
+ "\tsetcap cap_sys_nice+ep "; /* program_name */
+ static const char privilege_message_b[] = "\n\tsetcap cap_ipc_lock+ep ";
+ /* program_name */
+ static const char privilege_message_c[] = "\n\n"
+ "That will allow you to use a real-time scheduling priority and locked\n"
+ "memory while running as any user.\n"
+ "Alternatively, you can execute this program as root.\n\n";
+
+ static const char old_kernel_message[] =
+ "This kernel doesn't seem to have real-time facilities or memory locking.\n"
+ "If audio is sometimes interrupted, try a newer kernel.\n";
+
+ void
+ set_scheduler()
+ {
+ bool insufficient_privilege = false;
+ bool old_kernel = false;
+
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ // Put this process on the round-robin realtime scheduling queue at the
+ // minimum priority. Other real-time processes (perhaps portaudio) can
+ // run with a higher priority than this, but this process will run at
+ // a higher priority than all normal processes.
+ sched_param p;
+ int policy = SCHED_RR;
+
+ p.sched_priority = sched_get_priority_min(policy);
+ const int result = sched_setscheduler(0, policy, &p);
+ if ( result < 0 ) {
+ std::cerr << "sched_setscheduler: " << strerror(errno) << std::endl;
+ if ( errno == EINVAL )
+ old_kernel = true;
+ if ( errno == EPERM )
+ insufficient_privilege = true;
+ }
+#endif
+
+#ifdef _POSIX_MEMLOCK_RANGE
+ if ( mlockall(MCL_CURRENT|MCL_FUTURE) < 0 ) {
+ std::cerr << "mlockall: " << strerror(errno) << std::endl;
+ if ( errno == EINVAL )
+ old_kernel = true;
+ if ( errno == EPERM )
+ insufficient_privilege = true;
+ }
+#endif
+ if ( old_kernel )
+ std::cerr << old_kernel_message;
+ else if ( insufficient_privilege )
+ std::cerr << privilege_message_a;
+ std::cerr << program_name;
+ std::cerr << privilege_message_b;
+ std::cerr << program_name;
+ std::cerr << privilege_message_c;
+ }
+}