fixed the "user" kernel module getting the wrong IDs when creating tasks
when the user kernel module creates a task, it used to count the amount of processes in the system, which can lead to some processes having the same IDs as another, which causes havoc. this has been fixed by using the ID counter in the tsched kernel module.
This commit is contained in:
@@ -16,7 +16,7 @@ function module.init()
|
|||||||
local gpu = component.gpu
|
local gpu = component.gpu
|
||||||
local log = require("log")
|
local log = require("log")
|
||||||
|
|
||||||
local idCounter = 1
|
tsched.idCounter = 1
|
||||||
|
|
||||||
function _G._PUBLIC.tsched.runAsTask(path, ...)
|
function _G._PUBLIC.tsched.runAsTask(path, ...)
|
||||||
checkArg(1, path, "string")
|
checkArg(1, path, "string")
|
||||||
@@ -68,20 +68,27 @@ function module.init()
|
|||||||
checkArg(1, func, "function")
|
checkArg(1, func, "function")
|
||||||
checkArg(2, name, "string")
|
checkArg(2, name, "string")
|
||||||
local task = coroutine.create(func)
|
local task = coroutine.create(func)
|
||||||
local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = idCounter}
|
local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = tsched.idCounter }
|
||||||
if type(tsched.currentTask) == "table" and type(tsched.currentTask.id) == "number" then
|
if type(tsched.currentTask) == "table" and type(tsched.currentTask.id) == "number" then
|
||||||
taskInfo.parent = tsched.currentTask.id
|
taskInfo.parent = tsched.currentTask.id
|
||||||
taskInfo.user = tsched.currentTask.user
|
taskInfo.user = tsched.currentTask.user
|
||||||
end
|
end
|
||||||
table.insert(tsched.tasks, taskInfo)
|
table.insert(tsched.tasks, taskInfo)
|
||||||
idCounter = idCounter + 1
|
tsched.idCounter = tsched.idCounter + 1
|
||||||
if taskInfo.parent then
|
if taskInfo.parent then
|
||||||
log.kernel.info(
|
log.kernel.info(
|
||||||
("[tsched] Created task %s (PID %d) by parent PID %d as UID %d"):format(name, idCounter - 1, taskInfo.parent, taskInfo.user)
|
("[tsched] Created task %s (PID %d) by parent PID %d as UID %d"):format(
|
||||||
|
name,
|
||||||
|
tsched.idCounter - 1,
|
||||||
|
taskInfo.parent,
|
||||||
|
taskInfo.user
|
||||||
|
)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
taskInfo.user = 1 -- It's probably being run from kernel level
|
taskInfo.user = 1 -- It's probably being run from kernel level
|
||||||
log.kernel.info(string.format("[tsched] Created task %s (PID %d) as UID 1 (no parent found)", name, idCounter - 1))
|
log.kernel.info(
|
||||||
|
string.format("[tsched] Created task %s (PID %d) as UID 1 (no parent found)", name, tsched.idCounter - 1)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
return task, taskInfo
|
return task, taskInfo
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,17 +38,32 @@ function module.init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local task = coroutine.create(func)
|
local task = coroutine.create(func)
|
||||||
local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = #_PUBLIC.tsched.getTasks() + 1, ["user"] = userId}
|
local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = tsched.idCounter, ["user"] = userId }
|
||||||
if type(tsched.currentTask) == "table" and type(tsched.currentTask.id) == "number" then
|
if type(tsched.currentTask) == "table" and type(tsched.currentTask.id) == "number" then
|
||||||
taskInfo.parent = tsched.currentTask.id
|
taskInfo.parent = tsched.currentTask.id
|
||||||
|
else
|
||||||
|
log.kernel.info("debug: tsched.currentTask is " .. require("serialize").table(tsched.currentTask))
|
||||||
end
|
end
|
||||||
table.insert(tsched.tasks, taskInfo)
|
table.insert(tsched.tasks, taskInfo)
|
||||||
if taskInfo.parent then
|
if taskInfo.parent then
|
||||||
log.kernel.info(
|
log.kernel.info(
|
||||||
("[tsched (user)] Created task %s (PID %d) by parent PID %d as UID %d"):format(name, #_PUBLIC.tsched.getTasks(), taskInfo.parent, taskInfo.user)
|
("[tsched (user)] Created task %s (PID %d) by parent PID %d as UID %d"):format(
|
||||||
|
name,
|
||||||
|
#_PUBLIC.tsched.getTasks(),
|
||||||
|
taskInfo.parent,
|
||||||
|
taskInfo.user
|
||||||
|
)
|
||||||
|
)
|
||||||
|
log.kernel.info(
|
||||||
|
string.format(
|
||||||
|
"[tsched (user)] Created task %s (PID %d) as UID %d (no parent found)",
|
||||||
|
name,
|
||||||
|
#_PUBLIC.tsched.getTasks(),
|
||||||
|
taskInfo.user
|
||||||
|
)
|
||||||
)
|
)
|
||||||
log.kernel.info(string.format("[tsched (user)] Created task %s (PID %d) as UID %d (no parent found)", name, #_PUBLIC.tsched.getTasks(), taskInfo.user))
|
|
||||||
end
|
end
|
||||||
|
tsched.idCounter = tsched.idCounter + 1
|
||||||
return task, taskInfo
|
return task, taskInfo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user