2021-06-06 01:26:18 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2022-01-05 08:42:46 +00:00
|
|
|
* Copyright © 2017-2022 The Looking Glass Authors
|
2021-06-06 01:26:18 +00:00
|
|
|
* https://looking-glass.io
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2019-02-28 08:31:04 +00:00
|
|
|
|
2019-05-09 09:07:23 +00:00
|
|
|
#include "interface/platform.h"
|
|
|
|
#include "common/debug.h"
|
2019-05-09 12:06:58 +00:00
|
|
|
#include "common/option.h"
|
2021-01-14 10:07:28 +00:00
|
|
|
#include "common/stringutils.h"
|
2020-01-02 12:34:35 +00:00
|
|
|
#include "common/thread.h"
|
2019-05-09 09:07:23 +00:00
|
|
|
|
2022-01-26 10:50:56 +00:00
|
|
|
#include <ctype.h>
|
2019-03-01 01:54:15 +00:00
|
|
|
#include <stdlib.h>
|
2019-03-01 10:01:25 +00:00
|
|
|
#include <string.h>
|
2019-03-02 09:31:33 +00:00
|
|
|
#include <signal.h>
|
2019-03-04 06:08:49 +00:00
|
|
|
#include <errno.h>
|
2021-01-14 10:07:28 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <unistd.h>
|
2022-01-26 10:50:56 +00:00
|
|
|
#include <sys/utsname.h>
|
2019-03-01 01:54:15 +00:00
|
|
|
|
2019-03-01 10:01:25 +00:00
|
|
|
struct app
|
|
|
|
{
|
2020-01-03 03:56:13 +00:00
|
|
|
const char * executable;
|
2020-05-30 02:31:26 +00:00
|
|
|
char * dataPath;
|
2022-01-26 10:50:56 +00:00
|
|
|
char * osVersion;
|
2019-03-01 10:01:25 +00:00
|
|
|
};
|
|
|
|
|
2020-01-03 03:56:13 +00:00
|
|
|
struct app app = { 0 };
|
2019-05-11 01:21:18 +00:00
|
|
|
|
2019-02-28 08:31:04 +00:00
|
|
|
int main(int argc, char * argv[])
|
|
|
|
{
|
2021-07-07 13:05:46 +00:00
|
|
|
// initialize for DEBUG_* macros
|
|
|
|
debug_init();
|
|
|
|
|
2019-04-11 07:15:17 +00:00
|
|
|
app.executable = argv[0];
|
2020-05-30 02:31:26 +00:00
|
|
|
|
|
|
|
struct passwd * pw = getpwuid(getuid());
|
|
|
|
alloc_sprintf(&app.dataPath, "%s/", pw->pw_dir);
|
|
|
|
|
2019-05-09 12:06:58 +00:00
|
|
|
int result = app_main(argc, argv);
|
2020-05-30 02:31:26 +00:00
|
|
|
|
|
|
|
free(app.dataPath);
|
2022-01-26 10:50:56 +00:00
|
|
|
free(app.osVersion);
|
2019-05-09 12:06:58 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-01-03 03:53:56 +00:00
|
|
|
void sigHandler(int signo)
|
2019-05-09 12:06:58 +00:00
|
|
|
{
|
2020-01-03 03:53:56 +00:00
|
|
|
DEBUG_INFO("SIGINT");
|
|
|
|
app_quit();
|
|
|
|
}
|
2019-03-01 10:01:25 +00:00
|
|
|
|
2021-01-14 06:05:26 +00:00
|
|
|
bool app_init(void)
|
2020-01-03 03:53:56 +00:00
|
|
|
{
|
2019-03-02 09:31:33 +00:00
|
|
|
signal(SIGINT, sigHandler);
|
2019-05-09 12:06:58 +00:00
|
|
|
return true;
|
2019-02-28 08:31:04 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 06:05:26 +00:00
|
|
|
const char * os_getExecutable(void)
|
2019-04-11 07:15:17 +00:00
|
|
|
{
|
|
|
|
return app.executable;
|
2020-05-30 02:31:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 06:05:26 +00:00
|
|
|
const char * os_getDataPath(void)
|
2020-05-30 02:31:26 +00:00
|
|
|
{
|
|
|
|
return app.dataPath;
|
|
|
|
}
|
2021-02-03 22:42:54 +00:00
|
|
|
|
2022-02-07 03:39:42 +00:00
|
|
|
bool os_getAndClearPendingActivationRequest(void)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-03 22:42:54 +00:00
|
|
|
bool os_blockScreensaver()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-04 02:39:11 +00:00
|
|
|
|
|
|
|
void os_showMessage(const char * caption, const char * msg)
|
|
|
|
{
|
|
|
|
DEBUG_INFO("%s: %s", caption, msg);
|
|
|
|
}
|
2021-08-05 12:35:22 +00:00
|
|
|
|
|
|
|
bool os_hasSetCursorPos(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void os_setCursorPos(int x, int y)
|
|
|
|
{
|
|
|
|
}
|
2022-01-05 10:04:57 +00:00
|
|
|
|
|
|
|
KVMFROS os_getKVMFRType(void)
|
|
|
|
{
|
|
|
|
return KVMFR_OS_LINUX;
|
|
|
|
}
|
|
|
|
|
2022-01-26 10:50:56 +00:00
|
|
|
static const char * getPrettyName()
|
2022-01-05 10:04:57 +00:00
|
|
|
{
|
2022-01-26 10:50:56 +00:00
|
|
|
static char buffer[256];
|
|
|
|
|
|
|
|
FILE * fp = fopen("/etc/os-release", "r");
|
|
|
|
if (fp == NULL)
|
|
|
|
{
|
|
|
|
fp = fopen("/usr/lib/os-release", "r");
|
|
|
|
if (fp == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buffer, sizeof(buffer), fp))
|
|
|
|
{
|
|
|
|
if (strstr(buffer, "PRETTY_NAME"))
|
|
|
|
{
|
|
|
|
char * ptr = strchr(buffer, '=') + 1;
|
|
|
|
while (isspace(*ptr))
|
|
|
|
++ptr;
|
|
|
|
|
|
|
|
size_t len = strlen(ptr);
|
|
|
|
while (isspace(ptr[len - 1]))
|
|
|
|
--len;
|
|
|
|
|
|
|
|
if (*ptr == '"' || *ptr == '\'')
|
|
|
|
{
|
|
|
|
++ptr;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr[len] = '\0';
|
|
|
|
fclose(fp);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a line is too long, skip it.
|
|
|
|
while (buffer[strlen(buffer) - 1] != '\n')
|
|
|
|
if (!fgets(buffer, sizeof(buffer), fp))
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
fclose(fp);
|
2022-01-05 10:04:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-01-26 10:50:56 +00:00
|
|
|
const char * os_getOSName(void)
|
|
|
|
{
|
|
|
|
if (app.osVersion)
|
|
|
|
return app.osVersion;
|
|
|
|
|
|
|
|
const char * pretty = getPrettyName();
|
|
|
|
struct utsname utsname;
|
|
|
|
uname(&utsname);
|
|
|
|
|
|
|
|
if (!pretty)
|
|
|
|
alloc_sprintf(
|
|
|
|
&app.osVersion,
|
|
|
|
"%s %s on %s",
|
|
|
|
utsname.sysname,
|
|
|
|
utsname.release,
|
|
|
|
utsname.machine
|
|
|
|
);
|
|
|
|
else
|
|
|
|
alloc_sprintf(
|
|
|
|
&app.osVersion,
|
|
|
|
"%s, kernel: %s %s on %s",
|
|
|
|
pretty,
|
|
|
|
utsname.sysname,
|
|
|
|
utsname.release,
|
|
|
|
utsname.machine
|
|
|
|
);
|
|
|
|
|
|
|
|
return app.osVersion;
|
|
|
|
}
|
|
|
|
|
2022-01-05 10:04:57 +00:00
|
|
|
const uint8_t * os_getUUID(void)
|
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
return NULL;
|
|
|
|
}
|