mirror of
https://github.com/richardghirst/PiBits.git
synced 2024-11-28 12:24:11 +01:00
Allow dev_write to work per-process.
This commit is contained in:
parent
ef87ef88a7
commit
b1bb608d4c
@ -404,31 +404,38 @@ static ssize_t dev_read(struct file *filp,char *buf,size_t count,loff_t *f_pos)
|
|||||||
|
|
||||||
static ssize_t dev_write(struct file *filp,const char *buf,size_t count,loff_t *f_pos)
|
static ssize_t dev_write(struct file *filp,const char *buf,size_t count,loff_t *f_pos)
|
||||||
{
|
{
|
||||||
char* end_of_line=0;
|
char* str = 0;
|
||||||
static int idx=0;
|
struct process_data* const pdata = filp->private_data;
|
||||||
static char str[32];
|
if (0 == pdata) return 0;
|
||||||
static const int max_idx = sizeof(str) - 1;
|
|
||||||
|
|
||||||
if ((idx+count) > max_idx) count = max_idx-idx;
|
// Read user data into str
|
||||||
if (copy_from_user(str, buf+idx, count)) {
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
|
||||||
idx+=count;
|
|
||||||
str[idx] = '\0';
|
|
||||||
end_of_line = strchr(str, '\n');
|
|
||||||
if (NULL == end_of_line)
|
|
||||||
{
|
{
|
||||||
if (31 == idx) {
|
char* end_of_line=0;
|
||||||
// Full buf without '\n'
|
static const int max_idx = sizeof(pdata->cmd_str) - 1;
|
||||||
printk(KERN_WARNING "ServoBlaster: Failed to parse command (%s)\n", str);
|
int* const idx = &(pdata->cmd_idx);
|
||||||
return -EINVAL;
|
str = pdata->cmd_str;
|
||||||
}
|
|
||||||
return count; // Incomplete line.
|
|
||||||
}
|
|
||||||
|
|
||||||
// We've reached end of command, so terminate string at '\n' and reset idx.
|
if ((*idx+count) > max_idx) count = max_idx-*idx;
|
||||||
*end_of_line = '\0';
|
if (copy_from_user(str, buf+*idx, count)) {
|
||||||
idx=0;
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
*idx+=count;
|
||||||
|
str[*idx] = '\0';
|
||||||
|
end_of_line = strchr(str, '\n');
|
||||||
|
if (NULL == end_of_line)
|
||||||
|
{
|
||||||
|
if (31 == *idx) {
|
||||||
|
// Full buf without '\n'
|
||||||
|
printk(KERN_WARNING "ServoBlaster: Failed to parse command (%s)\n", str);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return count; // Incomplete line.
|
||||||
|
}
|
||||||
|
|
||||||
|
// End of command, so terminate string at '\n' and reset idx.
|
||||||
|
*end_of_line = '\0';
|
||||||
|
*idx=0;
|
||||||
|
}
|
||||||
|
|
||||||
// Process the complete user string.
|
// Process the complete user string.
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user