1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
package main
/*
#include "config.h"
#include <fcntl.h>
#include <libgen.h>
#include <sched.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <unistd.h>
#include "incus.h"
#include "memory_utils.h"
#include "mount_utils.h"
#include "syscall_numbers.h"
#include "syscall_wrappers.h"
void forkcoresched(void)
{
char *cur = NULL;
char *pidstr;
int hook;
int ret;
__u64 cookie;
// Check that we're root
if (geteuid() != 0)
_exit(EXIT_FAILURE);
// Get the subcommand
cur = advance_arg(false);
if (cur == NULL ||
(strcmp(cur, "--help") == 0 ||
strcmp(cur, "--version") == 0 || strcmp(cur, "-h") == 0))
_exit(EXIT_SUCCESS);
ret = core_scheduling_cookie_create_thread(0);
if (ret)
_exit(EXIT_FAILURE);
cookie = core_scheduling_cookie_get(0);
if (!core_scheduling_cookie_valid(cookie))
_exit(EXIT_FAILURE);
hook = atoi(cur);
switch (hook) {
case 0:
for (pidstr = cur; pidstr; pidstr = advance_arg(false)) {
ret = core_scheduling_cookie_share_to(atoi(pidstr));
if (ret)
_exit(EXIT_FAILURE);
cookie = core_scheduling_cookie_get(0);
if (!core_scheduling_cookie_valid(cookie))
_exit(EXIT_FAILURE);
}
break;
case 1:
pidstr = getenv("LXC_PID");
if (!pidstr)
_exit(EXIT_FAILURE);
ret = core_scheduling_cookie_share_to(atoi(pidstr));
if (ret)
_exit(EXIT_FAILURE);
cookie = core_scheduling_cookie_get(0);
if (!core_scheduling_cookie_valid(cookie))
_exit(EXIT_FAILURE);
break;
default:
_exit(EXIT_FAILURE);
}
_exit(EXIT_SUCCESS);
}
*/
import "C"
import (
"errors"
"github.com/spf13/cobra"
// Used by cgo
_ "github.com/lxc/incus/v6/shared/cgo"
)
type cmdForkcoresched struct {
global *cmdGlobal
}
func (c *cmdForkcoresched) command() *cobra.Command {
// Main subcommand
cmd := &cobra.Command{}
cmd.Use = "forkcoresched <hook> <PID> [...]"
cmd.Short = "Create new core scheduling domain"
cmd.Long = `Description:
Create new core scheduling domain
This command is used to move a set of processes into a new core scheduling
domain.
`
cmd.RunE = c.run
cmd.Hidden = true
return cmd
}
func (c *cmdForkcoresched) run(_ *cobra.Command, _ []string) error {
return errors.New("This command should have been intercepted in cgo")
}
|